我遇到了类似的问题,我需要使用 Junit 5 长时间运行 Junit 4.12 测试。添加 Junit 5 测试后,我得到了下一个错误:
[INFO] T E S T S 16:28:24 [INFO]
-------------------------------------------------------
16:28:26 [INFO]
16:28:26 [INFO] Results:
16:28:26 [INFO]
16:28:26 [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
16:28:26 [INFO]
16:28:26 [INFO]
------------------------------------------------------------------------
16:28:26 [INFO] BUILD SUCCESS
16:28:26 [INFO]
------------------------------------------------------------------------
我读到添加
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.2</version>
</dependency>
可以解决我的问题,但是当我尝试运行测试时,我收到了下一条消息
[INFO] T E S T S
16:12:57 [INFO] -------------------------------------------------------
16:12:58
16:12:58 +-------------------------------------------------------------------------------+
16:12:58 | WARNING: |
16:12:58 | The junit-platform-surefire-provider has been deprecated and is scheduled to |
16:12:58 | be removed in JUnit Platform 1.4. Please use the built-in support in Maven |
16:12:58 | Surefire >= 2.22.0 instead. |
16:12:58 | » https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven |
16:12:58 +-------------------------------------------------------------------------------+
16:12:58
最后下一个 pom 设置为我修复了它:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
.... More code here non relevant
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
</dependency>
.... More code here non relevant
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<dependenciesToScan>
<dependency>${group.id}:${test.project.name}</dependency>
</dependenciesToScan>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
现在,当我尝试运行 Junit 4.12 测试时,它们被找到并执行了。
更新
我注意到 log4j 日志存在一些问题,它只显示异常堆栈跟踪。 Junit5也停止工作。因此,经过更多测试我的 pom 文件的最终版本。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
.... More code here non relevant
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
.... More code here non relevant
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<dependenciesToScan>
<dependency>${group.id}:${test.project.name}</dependency>
</dependenciesToScan>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>