Lein test
以随机顺序运行我的函数。
我有两个修改相同数据的函数。我需要先运行第一个,然后再运行第二个。我的测试文件中的顺序
示例:
;;===============my file=============
;;this fails if x and y are not found.
(defn create-data [x y]
(go add x y))
;;if the update function doesn't find x and y it adds them so create-data fails when it runs after update-data
(defn update-data [x y]
(go update x y))
;;======my file test=======
(deftest create-test
(testing "this should run first"
(is (= 20 create-data)))
(deftest create-test
(testing "this should run second"
(is (= 20 update-data)))
所以我认为为这两个函数创建一个测试将使其工作,但事实并非如此。
(deftest test-create-update.
(testing "this should run second"
(is (= 20 create-data))
(is (= 20 update-data)))
我想要一个能够运行这两个函数的东西,但首先肯定会运行创建数据,并且无论结果如何(无论通过还是失败)都将运行更新数据。我的测试中两者都需要。他们单独工作。但我需要自动化测试。
最佳答案
您可以使用测试装置来创建和拆除测试环境。可以对所有测试或每个单独的测试执行此操作。
参见use-fixtures :
; Here we register my-test-fixture to be called once, wrapping ALL tests
; in the namespace
(use-fixtures :once my-test-fixture)
如果您想在多个命名空间上强制执行顺序,可以将它们包装在 my-test-fixture
中。
关于unit-testing - 一种链接测试的方法,在 Clojure 中一个在另一个之后运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36188072/