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
具有多个断言的Clojure测试_Clojure_Tdd - Fatal编程技术网

具有多个断言的Clojure测试

具有多个断言的Clojure测试,clojure,tdd,Clojure,Tdd,我开始学习如何为我的Clojure程序编写测试。 我有一个多断言的测试(调用is)。 我希望测试在第一次断言失败后立即停止运行。 这是我的测试: (deftest register-one-command (testing "Register-one-command" (do (is (= 0 (count @test/list-of-commands))) (test/add-to-list-of-commands ["A"]) (is (= 1

我开始学习如何为我的Clojure程序编写测试。 我有一个多断言的测试(调用
is
)。 我希望测试在第一次断言失败后立即停止运行。 这是我的测试:

(deftest register-one-command
  (testing "Register-one-command"
    (do
      (is (= 0 (count @test/list-of-commands)))
      (test/add-to-list-of-commands ["A"])
      (is (= 1 (count @test/list-of-commands))))))

如果第一个
失败了,我希望整个过程都失败。

最简单的方法就是将不同的测试打包成

(deftest register-one-command
  (testing "Register-one-command"
    (is (and
          (= 0 (count @test/list-of-commands))
          (test/add-to-list-of-commands ["A"])
          (= 1 (count @test/list-of-commands))))))

但是,如果可能的话,我会尝试重新构造测试,这样就不需要额外的复杂性。

谢谢您的编辑。我注意到代码的重新格式化,使右括号在同一行上,而不是在匹配的左括号下面。我是Clojure的新手,所以我可能做错了,但我喜欢开头括号下面的右括号,因为它使我更容易复制和粘贴单独的行。此外,当我编辑代码时,匹配开始括号和结束括号是很重要的,并不是每个编辑器都会为我突出显示。查看这篇文章,它不是关于测试,它讨论了如何做一个通用的如果成功那么。。。如果成功…->这基本上是一个错误的monad。