具有多个断言的 Clojure 测试

Clojure test with multiple assertions

我开始学习如何为我的 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))))))

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