我正在使用 JUnit 5.3.1 并使用 maven 运行测试。有一个参数化测试未运行。我正在使用 maven-surefire-plugin,这是来 self 的 pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>**/*Tests.java,**/*Test.java</include>
</includes>
</configuration>
</plugin>
...
</build>
当我运行 mvn test
命令时,这是输出的一部分:
运行 com.growthintel.elastic_plugin.cid_suppressions.CheckCompanyTest
测试运行:0,失败:0,错误:0,跳过:0,已用时间:0 秒 - 在 com.growthintel.elastic_plugin.cid_suppressions.CheckCompanyTest
从 CheckCompanyTest 文件中没有检测到任何测试! Maven 正在检测该文件,但未检测到该文件内的任何测试。是否有我没有遵循的参数化测试的命名约定?这是测试文件:
public class CheckCompanyTest {
private static Stream<Arguments> getListOfSuppressedFilePaths() {
...
}
@ParameterizedTest(name = "run #{index} with args: {arguments}")
@MethodSource("getListOfSuppressedFilePaths")
public void test_HasSuppressedCid(List<String> cidSuppressionFilePaths) {
...
}
最佳答案
您可以使用junit-platform-surefire-engine
,就像@Niby建议的那样,或者将您的maven-surefire-plugin
升级到2.22.0,并使用对 JUnit Jupiter 的内置支持:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version> <!-- Here -->
<configuration>
<includes>
<include>**/*Tests.java,**/*Test.java</include>
</includes>
</configuration>
</plugin>
关于java - JUnit 5 测试未运行/检测到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52553976/