Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 组合测试、检查和clojure测试_Unit Testing_Clojure - Fatal编程技术网

Unit testing 组合测试、检查和clojure测试

Unit testing 组合测试、检查和clojure测试,unit-testing,clojure,Unit Testing,Clojure,我无法使用测试。请与正常测试一起检查。我花了一整天的时间想弄清楚到底发生了什么,但我还是不确定。 这就是我现在拥有的: (deftest user-can-only-be-inserted-once (;normal test)) (defspec insert-one-user-should-let-me-retrieve-that-one-user gen-quantity (prop/for-all ; test.check test)) 现在,

我无法使用测试。请与正常测试一起检查。我花了一整天的时间想弄清楚到底发生了什么,但我还是不确定。 这就是我现在拥有的:

(deftest user-can-only-be-inserted-once
  (;normal test))

(defspec insert-one-user-should-let-me-retrieve-that-one-user
         gen-quantity
         (prop/for-all ; test.check test))
现在,只要在测试文件中的每次更改之后从控制台执行“lein test”,它就会按预期工作。但是,从草书repl或通过“lein quickie”使用quickie插件运行测试时,repl将重新加载不正确的名称空间

结果是,每当一个测试失败并且我修复了该测试时,它仍然会在repl中失败,所以看起来那里有些东西工作不正常

如果有人知道如何解决这个问题,我很乐意听到。我还想知道是否有人有一个不同的设置,它结合了正常测试和test.check,或者这是不打算工作的

谢谢, 斯文


更新事实上,我发现问题不在于normal和test.check的组合,而在于我试图检查断言的事实是针对特定案例的。在正常测试中,您可以使用(is)(抛出)断言(函数…来执行此操作,但当我在测试中尝试此操作时,检查它是否失败。

如果我正确理解您的更新,您的测试将抛出异常。如果未发生异常,则测试应失败

如果是这样,那么您需要在defspec中写入属性来捕获异常,将其作为值返回,并验证异常是否发生

你可以这样做:

(defn catcher [f]
  (try (f)
   (catch Throwable t t)))

(defspec some-specification-name
  (prop/for-all [...generator-bindings...]
    (not-nil? (catcher (my-function generated-values)))))

事实证明,在我这方面似乎有更多的错误。然而,由于你为我更新的问题提供了一个很好的解决方案,我会将此标记为已解决。谢谢。