从Clojure Repl和Leiningen运行测试 [英] Run tests from Clojure Repl and Leiningen
问题描述
作为clojure的新手,我已经使用leiningen创建一个示例项目
As a newbie to clojure, I have used leiningen to create a sample project with
lein new app first-project
这给了我这个目录
.
├── doc
│ └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│ └── first_project
│ └── core.clj
├── target
│ └── repl
│ ├── classes
│ └── stale
│ └── extract-native.dependencies
└── test
└── first_project
└── core_test.clj
不修改任何文件,我可以成功地唯一失败的测试
Without modifying any files, I can lauch successfully the only failing test with
lein test
...
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
Tests failed.
但是我无法从REPL使用运行测试执行相同操作
But I am unable to do the same from the REPL using run-tests
lein repl
first-project.core=> (use 'clojure.test)
nil
first-project.core=> (run-tests)
Testing first-project.core
Ran 0 tests containing 0 assertions.
0 failures, 0 errors.
{:type :summary, :pass 0, :test 0, :error 0, :fail 0}
我试过(但不工作)
(require 'first-project.core-test)
推荐答案
在上面的例子中,repl是在错误的命名空间。如果您将repl切换到 core_test
命名空间,它可能会更好。然后运行(run-tests)
。
In your example above the repl is in the wrong namespace. It may work better if you switch the repl to the core_test
namespace. and then run (run-tests)
.
(in-ns 'first-project.core-test)
(run-tests)
开发测试的另一个有趣的方法是从REPL运行它们直到他们工作,因为测试是正常的函数,额外元数据。
Another fun way of developing tests is to just run them from the REPL until they work, because tests are normal functions with some extra metadata.
(in-ns 'first-project.core-test)
(my-test)
这篇关于从Clojure Repl和Leiningen运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!