https://blog.csdn.net/huyuchengus/article/details/108975242
在 Spring 项目中运行测试的时候,得到错误:
TestEngine with ID 'junit-vintage' failed to discover tests” with Spring
这个错误的原因是 JUnit 的引擎,使用了 junit-vintage 引擎。
junit-vintage 是 Junit 4 中使用的引擎,如果你的项目使用了 Junit 5 的话,你需要在 spring-boot-starter-test 中将 JUnit 4 的引擎从测试中删除。
1. <dependency> 2. <groupId>org.springframework.boot</groupId> 3. <artifactId>spring-boot-starter-test</artifactId> 4. <scope>test</scope> 5. <exclusions> 6. <exclusion> 7. <groupId>org.junit.vintage</groupId> 8. <artifactId>junit-vintage-engine</artifactId> 9. </exclusion> 10. </exclusions> 11. </dependency>
junit-vintage-engine 和 junit-jupiter-engine 有什么不同
junit-vintage-engine
是 JUnit 4 中使用的测试引擎。 junit-jupiter-engine
是 JUnit 5 中使用的测试引擎。
如果你的 Spring 项目使用的新的 Spring Boot 版本的话,你应该默认使用了 JUnit 5 的引擎,因此为了兼容性,你需要在 spring-boot-starter-test 这个 POM 引用的时候将 JUnit 4 的引擎去除掉。
上面的这个配置你可以尝试下能解决你的问题。