我开始学习如何为我的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
失败,我希望整个事情失败。
答案 0 :(得分:3)
最简单的方法是将不同的测试包装在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))))))
但是,如果可能的话,我会尝试重新构建测试,这样就不需要额外的复杂性了。