如何使用 jUnit 测试运行器在 Intellij 中创建一个新的 Leiningen Clojure 项目?
How do I create a new Leiningen Clojure project in Intellj using the jUnit test runner?
我在 IntelliJ IDEA 2018.2.6 (Build #IU-182.5107.16)
中使用 Java 1.8
创建了一个新的骨架 Leiningen 项目。
我得到了 Error: Could not find or load main class cucumber.api.cli.Main
。我想改用 jUnit,所以我没有尝试修复 Cucumber 依赖项。
文件 > 项目结构 > 模块:.已验证测试文件夹是否标记为测试。
文件 > 项目结构 > 库 > + > 来自 Maven:添加了 junit:junit:4.12
和 Java 我的模块的文档。
运行 > 编辑配置:
- 删除 Cucumber Java 配置
- 添加 jUnit 配置
当我 运行 所有测试时,我收到一条 空测试套件 消息。
我尝试过重建项目、检查 IntelliJ 更新、使缓存无效、在项目配置模式的工作目录中使用绝对路径。
当我在终端运行lein test
时,检测到样本测试并打印断言
基本上,我如何使用 jUnit 测试在 Intellj 中创建一个新的 Leiningen Clojure 项目 运行ner 检测并 运行s 我的测试?
如果你需要,我已经把我的示例项目的source code推送到Github。
2020 年更新:
我不再使用 Leiningen 模板创建新项目(例如 lein new app XXXXX
)。相反,我有一个使用 git
克隆的模板项目,我将其用作新 Clojure 和 ClojureScript 项目的基础:
开始新项目的例子:
> git clone https://github.com/io-tupelo/clj-template.git myproj
Cloning into 'myproj'...
此时,您可以编辑 project.clj
和源文件以更改 and/or 添加命名空间等
旧答案
我不在 IntelliJ 中创建项目。我在命令行创建它们,然后将它们添加到 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/
然后在 IntelliJ 中做
File -> New -> Project from existing sources....
在弹出窗口 window 中,导航到新目录并双击 project.clj
文件。
- 保留根目录相同 (
~/tmp/demo.sample
)
- 将选择保留为
sample:0.1.0-SNAPSHOT
(这取自 project.clj
)
- Select 你的 JDK(Java 至少 10,我希望!)
- 保留项目名称相同(即
sample
)
- 点击
Finish
此时,您可以编辑 project.clj
以添加 JUnit 部门或您想要的任何其他内容。然后这将确定您需要在 ./test
子目录树中制作的任何模组。
做完后
lein new app sample
您将在 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}})
以上只是骨架。
更多信息请看:
我在 IntelliJ IDEA 2018.2.6 (Build #IU-182.5107.16)
中使用 Java 1.8
创建了一个新的骨架 Leiningen 项目。
我得到了 Error: Could not find or load main class cucumber.api.cli.Main
。我想改用 jUnit,所以我没有尝试修复 Cucumber 依赖项。
文件 > 项目结构 > 模块:.已验证测试文件夹是否标记为测试。
文件 > 项目结构 > 库 > + > 来自 Maven:添加了 junit:junit:4.12
和 Java 我的模块的文档。
运行 > 编辑配置:
- 删除 Cucumber Java 配置
- 添加 jUnit 配置
当我 运行 所有测试时,我收到一条 空测试套件 消息。
我尝试过重建项目、检查 IntelliJ 更新、使缓存无效、在项目配置模式的工作目录中使用绝对路径。
当我在终端运行lein test
时,检测到样本测试并打印断言
基本上,我如何使用 jUnit 测试在 Intellj 中创建一个新的 Leiningen Clojure 项目 运行ner 检测并 运行s 我的测试?
如果你需要,我已经把我的示例项目的source code推送到Github。
2020 年更新:
我不再使用 Leiningen 模板创建新项目(例如 lein new app XXXXX
)。相反,我有一个使用 git
克隆的模板项目,我将其用作新 Clojure 和 ClojureScript 项目的基础:
开始新项目的例子:
> git clone https://github.com/io-tupelo/clj-template.git myproj
Cloning into 'myproj'...
此时,您可以编辑 project.clj
和源文件以更改 and/or 添加命名空间等
旧答案
我不在 IntelliJ 中创建项目。我在命令行创建它们,然后将它们添加到 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/
然后在 IntelliJ 中做
File -> New -> Project from existing sources....
在弹出窗口 window 中,导航到新目录并双击 project.clj
文件。
- 保留根目录相同 (
~/tmp/demo.sample
) - 将选择保留为
sample:0.1.0-SNAPSHOT
(这取自project.clj
) - Select 你的 JDK(Java 至少 10,我希望!)
- 保留项目名称相同(即
sample
) - 点击
Finish
此时,您可以编辑 project.clj
以添加 JUnit 部门或您想要的任何其他内容。然后这将确定您需要在 ./test
子目录树中制作的任何模组。
做完后
lein new app sample
您将在 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}})
以上只是骨架。
更多信息请看: