I'm trying to create my first tests on Clojure. I wrote this file . When I run:
lein test
I got:
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 "grayson@me.com", :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 "samantha@yahoo.com", :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.
So, it looks like the test is executed twice but the first time with errors and the second correctly. I noticed the line:
clojure.test/run-tests test.clj: 768 (repeats 2 times)
but I don't why the file is called twice and why the first time some tests are "skipped". If I remove the line:
(run-tests)
from the file, only the first (and wrong) time is executed.
You don't need (run-tests)
in the file. The command lein test
will find all tests defined via deftest
and run them for you.
Here is a sample project you can clone and modify (try it w/o changes first to see an example of how it should look).
It is possible that your mount
is doing something strange. I personally don't like the "silent magic" that mount uses. Also, I'm surprised it works for zentaur.config, zentaur.handler, and zentaur.db.core when they are not part of the (:require ...)
expression.
As Alan mentioned, (run-tests) is not necessary, that option usually is used in combination with " with-test ".
As far as I could understand, before execute them, "lein test" gathers all the "deftest" in a vector that doesn't reflect the order in the file, so the last "deftest" are executed first. My solution was to nest the three "(testing " sections that I need to be executed sequentially in a "parent" deftest .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.