简体   繁体   English

在莱宁根进行测试

[英]Testing in leiningen

I am writing a small Clojure project using leiningen with the following directory structure:我正在使用具有以下目录结构的 leiningen 编写一个小型 Clojure 项目:

project
+ src
  + org/example/project/core.clj
+ test
  + org/example/project/core.clj

When I run lein test , it reports that it ran 0 tests with 0 failures, but I purposely put a test designed to fail in the test/.../core.clj file.当我运行lein test ,它报告它运行了 0 个测试,0 个失败,但我故意在 test/.../core.clj 文件中放置了一个旨在失败的测试。

I added the line :test-path test to my project.clj file and when I re-ran, got the error:我将:test-path test行添加到我的project.clj文件中,当我重新运行时,出现错误:

Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.Symbol (NO_SOURCE_FILE:0)
    at clojure.lang.Compiler.eval(Compiler.java:5440)
    at clojure.lang.Compiler.eval(Compiler.java:5391)
    at clojure.core$eval.invoke(core.clj:2382)
    at clojure.main$eval_opt.invoke(main.clj:235)
    at clojure.main$initialize.invoke(main.clj:254)
    at clojure.main$script_opt.invoke(main.clj:270)
    at clojure.main$main.doInvoke(main.clj:354)
    at clojure.lang.RestFn.invoke(RestFn.java:458)
    at clojure.lang.Var.invoke(Var.java:377)
    at clojure.lang.AFn.applyToHelper(AFn.java:174)
    at clojure.lang.Var.applyTo(Var.java:482)
    at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.Symbol
    at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:471)
    at clojure.java.io$fn__7328$G__7323__7333.invoke(io.clj:34)
    at clojure.java.io$file.invoke(io.clj:401)
    at leiningen.util.ns$namespaces_in_dir.invoke(ns.clj:38)
    at leiningen.test$test.doInvoke(test.clj:45)
    at clojure.lang.RestFn.invoke(RestFn.java:411)
    at clojure.lang.Var.invoke(Var.java:365)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:482)
    at clojure.core$apply.invoke(core.clj:542)
    at leiningen.core$apply_task.invoke(core.clj:156)
    at leiningen.core$_main.doInvoke(core.clj:212)
    at clojure.lang.RestFn.applyTo(RestFn.java:138)
    at clojure.core$apply.invoke(core.clj:540)
    at leiningen.core$_main.invoke(core.clj:217)
    at user$eval167.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.Compiler.eval(Compiler.java:5424)
    ... 11 more

I am running Clojure 1.2 and the latest lein (1.3.1).我正在运行 Clojure 1.2 和最新的 lein (1.3.1)。

Looks like a problem with either clojure.core or the lein code.看起来像是 clojure.core 或 lein 代码的问题。

Had the same issue.有同样的问题。 After a while I noticed that leins default path to tests are:过了一会儿,我注意到 leins 的默认测试路径是:

test/{project-name}/test/{file-under-test}.clj
                    ^^^^

Note an extra test directory in the path.请注意路径中的额外test目录。

As for the source layout.至于源布局。 I think you basically shadow your test with the real core.clj file.我认为您基本上使用真实的 core.clj 文件来隐藏您的测试。 That's probably why clojure.test doesn't find any tests.这可能就是clojure.test找不到任何测试的原因。 Did you try a different namespace and file name?您是否尝试了不同的命名空间和文件名? eg.例如。 test/example/project/test_core.clj . test/example/project/test_core.clj

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM