[英]How do I create a new Leiningen Clojure project in Intellj using the jUnit test runner?
I created a new skeleton Leiningen project using Java 1.8
in IntelliJ IDEA 2018.2.6 (Build #IU-182.5107.16)
.我在IntelliJ IDEA 2018.2.6 (Build #IU-182.5107.16)
使用Java 1.8
创建了一个新的框架 Leiningen 项目。
I got an Error: Could not find or load main class cucumber.api.cli.Main
.我收到一个Error: Could not find or load main class cucumber.api.cli.Main
。 I wanted to use jUnit instead so I didn't try fix the Cucumber dependency.我想改用 jUnit,所以我没有尝试修复 Cucumber 依赖项。
File > Project Stucture > Module :.文件 > 项目结构 > 模块:. Verified that the test folder is marked as Tests.验证测试文件夹是否标记为测试。
File > Project Structure > Libraries > + > From Maven : Added junit:junit:4.12
with Transitive dependencies and JavaDocs to my module.文件 > 项目结构 > 库 > + > 来自 Maven :向我的模块添加了带有传递依赖项和 JavaDocs 的junit:junit:4.12
。
Run > Edit Configurations :运行 > 编辑配置:
When I run all tests, I am presented with an Empty test suite message.当我运行所有测试时,我会看到一条Empty test suite消息。
I have tried rebuilding the project, checking for IntelliJ updates, invalidating the cache, using an absolute path in the Working directory in the project configurations modal.我尝试重建项目,检查 IntelliJ 更新,使缓存无效,使用项目配置模式中工作目录中的绝对路径。
When I run lein test
in the terminal, the sample test is detected and the assertion is printed out.当我在终端中运行lein test
时,会检测到示例测试并打印出断言。
Essentially, how do I create a new Leiningen Clojure project in Intellj using the jUnit test runner detects and runs my tests?本质上,如何使用 jUnit 测试运行器检测并运行我的测试在 Intellj 中创建一个新的 Leiningen Clojure 项目?
If you need it, I have pushed the source code of my example project to Github.如果你需要它,我已经把我的示例项目的源代码推送到了 Github。
I no longer use Leiningen templates to create a new project (eg lein new app XXXXX
).我不再使用 Leiningen 模板来创建新项目(例如lein new app XXXXX
)。 Instead, I have a template project that I clone using git
, and I use as the basis for new Clojure and ClojureScript projects:相反,我有一个使用git
克隆的模板项目,我将其用作新 Clojure 和 ClojureScript 项目的基础:
Example of starting a new project:开始一个新项目的例子:
> git clone https://github.com/io-tupelo/clj-template.git myproj
Cloning into 'myproj'...
At this point, you can edit the project.clj
and the source files to change and/or add namespaces, etc.此时,您可以编辑project.clj
和源文件以更改和/或添加命名空间等。
I don't create projects from within IntelliJ.我不在 IntelliJ 中创建项目。 I create them at the command line and then add them to IntelliJ/IDEA + Cursive.我在命令行创建它们,然后将它们添加到 IntelliJ/IDEA + Cursive。
~/tmp/demo > lein new app sample
Generating a project called sample based on the 'app' template.
~/tmp/demo > cd sample
~/tmp/demo/sample > ls -al
total 56
drwxrwxr-x 6 alan alan 4096 Nov 18 21:19 ./
drwxrwxr-x 3 alan alan 4096 Nov 18 21:19 ../
-rw-rw-r-- 1 alan alan 766 Nov 18 21:19 CHANGELOG.md
drwxrwxr-x 2 alan alan 4096 Nov 18 21:19 doc/
-rw-rw-r-- 1 alan alan 99 Nov 18 21:19 .gitignore
-rw-rw-r-- 1 alan alan 136 Nov 18 21:19 .hgignore
-rw-rw-r-- 1 alan alan 11219 Nov 18 21:19 LICENSE
-rw-rw-r-- 1 alan alan 359 Nov 18 21:19 project.clj
-rw-rw-r-- 1 alan alan 463 Nov 18 21:19 README.md
drwxrwxr-x 2 alan alan 4096 Nov 18 21:19 resources/
drwxrwxr-x 3 alan alan 4096 Nov 18 21:19 src/
drwxrwxr-x 3 alan alan 4096 Nov 18 21:19 test/
Then within IntelliJ do然后在 IntelliJ 中做
File -> New -> Project from existing sources....
in the pop-up window, navigate to the new dir and double-click on the project.clj
file.在弹出窗口中,导航到新目录并双击project.clj
文件。
~/tmp/demo.sample
)保持根目录相同( ~/tmp/demo.sample
)sample:0.1.0-SNAPSHOT
(this is taken from project.clj
)将选择保留为sample:0.1.0-SNAPSHOT
(这是从project.clj
)sample
)保持项目名称相同(即sample
)Finish
单击Finish
At this point, you can edit project.clj
to add JUnit deps or anything else you want.此时,您可以编辑project.clj
以添加 JUnit deps 或您想要的任何其他内容。 This will then determine any mods you need to make in the ./test
subdir tree.这将确定您需要在./test
树中制作的任何模组。
After doing做完之后
lein new app sample
you will see in sample/project.clj您将在 sample/project.clj 中看到
(defproject sample "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:main ^:skip-aot sample.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
The above is just the bare bones.以上只是裸露的骨头。
For more info, please see:有关更多信息,请参阅:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.