[英]A way to chain the test, one running after the other in clojure?
Lein test
runs my functions in random order. Lein test
以随机顺序运行我的功能。
I have two functions that modify the same data. 我有两个函数可以修改相同的数据。 I need the first one running first and the second one after that.
我需要先运行第一个,然后再运行第二个。 The order in my test firles
我的测试顺序
Example: 例:
;;===============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)))
so I thought creating one test for both functions will make it work but it doesn't. 因此,我认为为这两个功能创建一个测试将使其正常工作,但没有成功。
(deftest test-create-update.
(testing "this should run second"
(is (= 20 create-data))
(is (= 20 update-data)))
I want something that will run both functions but will run create-data first for sure and regardless of the result (whether passed or failed) will run the update-data. 我想要可以同时运行这两个功能但首先要运行创建数据的东西,无论结果(通过还是失败)都将运行更新数据。 I need both in my test.
我的考试都需要。 Individually they work.
他们各自工作。 but i need automated testing.
但是我需要自动测试。
You could use test fixtures to create and tear down test environments. 您可以使用测试夹具来创建和拆除测试环境。 This can be done for all tests, or on every individual tests.
可以针对所有测试或每个单独的测试执行此操作。
See use-fixtures : 参见使用夹具 :
; Here we register my-test-fixture to be called once, wrapping ALL tests
; in the namespace
(use-fixtures :once my-test-fixture)
If you want to enforce order over several namespaces, you could wrap them in my-test-fixture
. 如果要对多个名称空间强制执行顺序,则可以将它们包装在
my-test-fixture
。
Your intuition for creating one test for both functions is a fine approach. 为这两个功能创建一个测试的直觉是一个很好的方法。 The issue you are having is most likely not related to testing.
您遇到的问题很可能与测试无关。
The code you posted (go add xy)
suggest you are using core.async. 您发布的代码
(go add xy)
表明您正在使用core.async。 There are some problems: 有一些问题:
(go add xy)
does not perform any functions, it just returns y. (go add xy)
不执行任何功能,它仅返回y。 You probably want (!< (go (add xy)))
(!< (go (add xy)))
I believe the real problem here is with the code, not the tests. 我相信这里的真正问题是代码,而不是测试。 Or if the code "works" then it is because you have no blocking in your test.
或者,如果代码“有效”,那是因为您的测试没有阻塞。 Can you please provide more detail on what
go
and add
are in your context? 能否请你提供什么更详细的
go
和add
在你的背景?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.