我正在尝试在Clojure上创建我的第一个测试。我写了this file。当我运行时:
lein test
我知道了:
ERROR in (update-question) (core.clj:32)
Uncaught exception, not in assertion.
expected: nil
actual:
clojure.core/require core.clj: 6007 (repeats 2 times)
clojure.core/load-libs core.clj: 5969
clojure.core/load-libs core.clj: 5985
clojure.test/run-tests test.clj: 768 (repeats 2 times)
clojure.core/apply core.clj: 667
clojure.lang.ExceptionInfo: Parameter Mismatch: :id parameter data not found.
java.lang.Exception: Exception in :get-one-question
FAIL in (create-answer) (tests_test.clj:63)
Create a new answer
expected: (not (nil? (:ordnen answer)))
actual: (not (not true))
FAIL in (create-answer) (tests_test.clj:64)
Create a new answer
expected: nil
actual: "Some not so cool answer"
diff: + "Some not so cool answer"
2020-03-05 17:24:12,124 [main] INFO zentaur.models.tests-test - >>> PA @first-user @first-user >>>>> {:email "[email protected]", :fname "Grayson", :lname "Barr", :active true, :id 72, :role_id 1, :uuid "efc8c516-04f1-4b22-a983-ed1e9c4f0da7"}
Ran 5 tests containing 7 assertions.
**2 failures, 1 errors.**
Testing zentaur.models.tests-test
2020-03-05 17:24:12,233 [main] INFO zentaur.models.tests-test - >>> PARAM @first-question@first-question@first-question >>>>> {:explanation "Explanation", :reviewed_fact false, :question "Some cool Question", :points 2, :hint "Some hint", :qtype 2, :updated_at #time/instant "2020-03-05T23:24:12Z", :reviewed_cr false, :active true, :id 71, :user_id 1, :origin 0, :fulfill nil, :created_at #time/instant "2020-03-05T23:24:12Z", :reviewed_lang false}
2020-03-05 17:24:12,849 [main] INFO zentaur.models.tests-test - >>> PA @first-user @first-user >>>>> {:email "[email protected]", :fname "Samantha", :lname "Good", :active true, :id 73, :role_id 1, :uuid "16d3eea4-3ed2-4636-a753-7fc0ec381e77"}
Ran 5 tests containing 8 assertions.
0 failures, 0 errors.
因此,看起来该测试执行了两次,但是第一次出现错误,第二次正确。我注意到了这一行:
clojure.test/run-tests test.clj: 768 (repeats 2 times)
但是我不知道为什么文件被两次调用以及为什么第一次“跳过”某些测试。如果我删除该行:
(run-tests)
从文件开始,仅执行第一次(也是错误的)时间。
您在文件中不需要(run-tests)
。命令lein test
将找到通过deftest
定义的所有测试,并为您运行它们。
这里是a sample project,您可以克隆和修改(尝试不做任何更改以查看其外观示例)。
[mount
可能正在做一些奇怪的事情。我个人不喜欢坐骑使用的“沉默魔术”。另外,令我惊讶的是,当它们不是(:require ...)
表达式的一部分时,它也可以用于zentaur.config,zentaur.handler和zentaur.db.core。