Surefire 2.22.2 在删除提供程序依赖项后找不到 junit 测试



第一次发帖!我尝试浏览所有其他有关万无一失问题的帖子,但无济于事,因此任何帮助将不胜感激。

我目前正在尝试处理我的项目中的"junit-platform-surefire-provider已被弃用"警告。正在使用 surefire 的 2.22.2 版本,目前可以找到我们项目中的所有 junit jupiter 测试。

警告: junit-platform-surefire-provider已被弃用,并计划在 在 JUnit 平台 1.4 中删除。请使用 Maven 中的内置支持 万无一失>= 2.22.0 代替。 https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven

找到 55 个测试的测试结果

当我尝试从插件中删除 junit-platform-surefire-provider 和 jupiter-engine 依赖项时,会出现这个问题。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>

这个提供程序将被弃用,我正在尝试摆脱它。我遵循了 https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven 的文档,以便尝试使用Maven Surefire中的内置支持。除了删除这两个依赖项之外,我还在 POM 文件的部分添加了以下两个依赖项。

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>

完成此操作后,构建将完成,但它不再找到任何测试。

找到零测试的测试结果

我错过了什么吗?

更新

有同样的问题

  • Maven 3.6.0
  • Maven-surefire-plugin 2.22.2
  • JUnit 5.7.0
  • Java jdk 1.8.261

添加到绒球上.xml

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
</dependency>    
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
</dependency>
<!--.... other dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<!--.... other plugins -->
</plugins>
</build>

工作正常并运行我所有的测试

我遇到了类似的问题,我需要使用 Junit 4.12 运行很长时间 5 测试。添加 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>

最新更新