在IntelliJ IDEA中包含JUnit 5依赖项

Sta*_*lfi 11 java junit intellij-idea junit5

来自jetbrains博客:

IntelliJ IDEA支持实际运行为JUnit 5编写的测试的能力 - 不需要使用其他库(例如Gradle或Maven插件),您只需要包含JUnit 5依赖项.

我是Java和IntelliJ IDEA的新手,我不清楚使用Junit 5进行测试应该采取哪些步骤.

Cra*_*der 16

如果您的项目是基于Maven或Gradle的,则通过pom.xml或添加依赖项build.gradle,否则您只需将.jar文件添加到Module Dependencies.

IDE可以帮助您,按红色代码Alt+ Enter:

添加库

以下依赖项将从Maven存储库下载并添加到类路径中:

DEPS

  • 从http://www.jetbrains.com/idea/download/index.html尝试最新的IDE版本. (2认同)

小智 7

我通过将它添加到我的 pom 来完成这项工作:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.0.0-M4</version>
    <scope>test</scope>
</dependency>       
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.0.0-M4</version>
    <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)