在 IntelliJ IDEA 中包含 JUnit 5 依赖项

2022-09-02 09:33:01

来自 jetbrains 博客

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

我是Java和IntelliJ IDEA的新手,我不清楚使用Junit 5进行测试应该做些什么步骤。


答案 1

如果您的项目是基于 Maven 或 Gradle 的,则通过 或 添加依赖项,否则您只需将文件添加到模块依赖项即可pom.xmlbuild.gradle.jar

IDE可以帮助您,请在红色代码上按+:AltEnter

add library

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

deps


答案 2

我通过将其添加到我的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>

推荐