我开始学习如何为我的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))))))
如果第一个is
失败,我希望整个事情都会失败。
最简单的方法就是将不同的测试包装在and
(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))))))
,如果可能的话,我会尝试重组测试,以使这种额外的复杂性不必要。