我正在使用Junit在Netbeans的Maven项目中测试一些代码。指定的依赖项是Junit 4.12 (在pom.xml中)。
然而,当我尝试编译时,我得到了一个编译器错误:
error: package org.junit.jupiter.api does not exist
在这一行:import org.junit.jupiter.api.Test;
我怀疑这是Junit4/Junit5的事情,因为当我在IntelliJ中打开项目的旧版本时,它会将Junit5列为依赖项。我应该只使用Junit5吗?
任何帮助解决构建错误的人都将不胜感激!
发布于 2017-07-19 03:35:57
在开始编写测试之前,您需要注入jupiter
artefact
Group ID: org.junit.jupiter
Artifact ID: junit-jupiter-api
Version: 5.0.0-M5
JUnit Jupiter
是JUnit 5
的子模块,因此需要使用JUnit 5
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M5</version>
<scope>test</scope>
</dependency>
发布于 2018-11-13 12:58:04
我觉得你的问题跟<scope>test</scope>
有关
您的测试类应该在测试包中。
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
你的测试应该在这里
发布于 2019-07-23 21:08:07
在我的例子中,它是通过在app中添加下面这行代码来工作的: build.gradle
dependencies {
implementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
}
https://stackoverflow.com/questions/45175418
复制相似问题