我用 JUnit 5 写了一个简单的测试方法:
public class SimlpeTest {
@Test
@DisplayName("Some description")
void methodName() {
// Testing logic for subject under test
}
}
但是当我运行 mvn test
时,我得到:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running SimlpeTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
不知何故,surefire 没有认出那个测试类。我的 pom.xml
看起来像:
<properties>
<java.version>1.8</java.version>
<junit.version>5.0.0-SNAPSHOT</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
知道如何使这项工作吗?
原文由 Ali Dehghani 发布,翻译遵循 CC BY-SA 4.0 许可协议
截至今天,
maven-surefire-plugin
还 没有完全支持 JUnit 5 。关于在 SUREFIRE-1206 中添加此支持存在未解决的问题。因此,您需要使用 自定义提供程序。 JUnit 团队已经开发了一个;从 用户指南 中,您需要添加
junit-platform-surefire-provider
提供程序和TestEngine
新 API 的实现:另外,一定要声明
junit-jupiter-api
范围为test
--- 的依赖项: