[英]Unit test if event handler called promises one after the other (synchronously)
[英]A way to chain the test, one running after the other in clojure?
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)))
我想要可以同時運行這兩個功能但首先要運行創建數據的東西,無論結果(通過還是失敗)都將運行更新數據。 我的考試都需要。 他們各自工作。 但是我需要自動測試。
您可以使用測試夾具來創建和拆除測試環境。 可以針對所有測試或每個單獨的測試執行此操作。
參見使用夾具 :
; 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
。
為這兩個功能創建一個測試的直覺是一個很好的方法。 您遇到的問題很可能與測試無關。
您發布的代碼(go add xy)
表明您正在使用core.async。 有一些問題:
(go add xy)
不執行任何功能,它僅返回y。 您可能想要(!< (go (add xy)))
我相信這里的真正問題是代碼,而不是測試。 或者,如果代碼“有效”,那是因為您的測試沒有阻塞。 能否請你提供什么更詳細的go
和add
在你的背景?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.