unit-testing - 一种链接测试的方法,在 Clojure 中一个在另一个之后运行?

标签 unit-testing clojure leiningen clojure.test

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/

相关文章:

windows - Cursive 无法定位到什么 Leiningen 路径? (IntelliJ Clojure 集成开发环境)

java - Mockito - 不可能 stub 模拟对象

java - Spock 模拟验证返回 0 次调用

javascript - 如何对调用 getJSON 的 javascript 函数进行单元测试

clojure - 在clojure中懒惰地构建集合

serialization - 在 clojure 中序列化持久数据结构

clojure - 如何让 Lein 与 JFreeChart 和 Dejcartes 配合使用?

python - 如果字典可以通过 `==` 进行比较,为什么需要 assertDictEqual ?

java - 现实世界中的 Clojure 和 Java 互操作

clojure - 如何从另一个目录运行 lein(没有 cd 到项目目录)?