具有多个断言的Clojure测试 [英] Clojure test with multiple assertions
本文介绍了具有多个断言的Clojure测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始学习如何为Clojure程序编写测试.我有一个包含多个断言的测试(对 is
的调用).我希望测试在第一个断言失败后立即停止运行.这是我的测试:
I am starting to learn how to write tests for my Clojure program.
I have a test with multiple assertions (calls to is
).
I want the test to stop running as soon as the first assertion fails.
Here is my test:
(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))))))
如果第一个是
失败,我希望整个事情都失败.
If the first is
fails, I want the whole thing to fail.
推荐答案
最简单的方法是将不同的测试包装在和
The simplest way is to just wrap the different tests in an 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))))))
但是,如果可能的话,我会尝试重组测试,以免不必要的额外复杂性.
If possible, however, I would try to restructure the tests so that this extra bit of complexity is unnecessary.
这篇关于具有多个断言的Clojure测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文