【问题标题】:Clojure. "lein test" executes file twice克洛朱尔。 “lein test”两次执行文件
【发布时间】:2020-03-05 23:41:51
【问题描述】:

我正在尝试在 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 "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.

所以,看起来测试执行了两次,但第一次出错,第二次正确。我注意到这条线:

            clojure.test/run-tests        test.clj:  768 (repeats 2 times)

但我不知道为什么文件被调用两次以及为什么第一次“跳过”某些测试。如果我删除该行:

  (run-tests)

从文件中,只执行第一次(也是错误的)时间。

【问题讨论】:

    标签: clojure tdd clojurescript leiningen


    【解决方案1】:

    文件中不需要(run-tests)。命令lein test 将查找通过deftest 定义的所有测试并为您运行它们。

    这里是a sample project,您可以克隆和修改(先尝试不进行更改,以查看其外观示例)。


    您的mount 可能正在做一些奇怪的事情。我个人不喜欢坐骑使用的“无声魔法”。此外,当 zentaur.config、zentaur.handler 和 zentaur.db.core 不是 (:require ...) 表达式的一部分时,我很惊讶。

    【讨论】:

      【解决方案2】:

      正如 Alan 所说,(运行测试)不是必需的,该选项通常与“with-test”结合使用。

      据我所知,在执行它们之前,“lein test”将所有“deftest”收集在一个不反映文件顺序的向量中,因此最后一个“deftest”首先执行。我的解决方案是将我需要按顺序执行的三个“(测试”部分)嵌套在“父”deftest中。

      【讨论】:

        猜你喜欢
        • 2018-10-15
        • 2014-06-06
        • 1970-01-01
        • 1970-01-01
        • 2018-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多