简体   繁体   English

如何使用 jUnit 测试运行程序在 Intellj 中创建新的 Leiningen Clojure 项目?

[英]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 :运行 > 编辑配置

  • Remove Cucumber Java configuration删除 Cucumber Java 配置
  • Add jUnit configuration添加 jUnit 配置

jUnit 的运行/调试配置

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。


Update 2020: 2020 年更新:

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和源文件以更改和/或添加命名空间等。


Old Answer旧答案

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文件。

  1. Leave the root dir the same ( ~/tmp/demo.sample )保持根目录相同( ~/tmp/demo.sample
  2. Leave selection as sample:0.1.0-SNAPSHOT (this is taken from project.clj )将选择保留为sample:0.1.0-SNAPSHOT (这是从project.clj
  3. Select your JDK (Java 10 at least, I hope!)选择您的 JDK(我希望至少是 Java 10!)
  4. Leave the Project Name the same (ie sample )保持项目名称相同(即sample
  5. Click 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.

相关问题 无法使用 Leiningen 使用 Cursive 运行 Clojure 项目 - Can not run Clojure project with Cursive using Leiningen 除了使用集成测试运行器在IntelliJ IDEA项目中以“IntegrationTest”结尾的所有JUnit单元测试之外,我该如何运行? - How can I run all JUnit unit tests except those ending in “IntegrationTest” in my IntelliJ IDEA project using the integrated test runner? 如何使用La Clojure插件在Java项目中创建clojure文件? - How do I create a clojure file in a Java project using La Clojure plugin? 在IDE中使用Clojure和Leiningen - Using clojure and leiningen with IDEs 我如何在 intellj 上正确编译 jnativehook? - How do i correctly compile jnativehook on intellj? 你如何在Intellj上分享你的Scala项目? - How do you share your Scala project on Intellj? Java Intellj:如何再次自动化Java项目作为程序参数的测试文件列表并比较输出? - Java Intellj: How to automate java project again a list of test files as program arguments and compare output? 对于 New Project 和 New Module,Spring Initializr 窗格在 IntellJ 中都是空白的 - Spring Initializr pane is blank in IntellJ, for both New Project and New Module 我如何要求 intellj 重新编制索引 - How can I ask intellj to reindex 在IntelliJ中使用Spring 4.1和JUnit4 Runner运行JUnit Jupiter测试 - Run JUnit Jupiter test with Spring 4.1 and JUnit4 Runner in IntelliJ
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM