JUnit 5 測試 Spring 引擎的時候提示 junit-vintage 錯誤


在 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 的引擎從測試中刪除。

        <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </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 的引擎去除掉。

 

 

上面的這個配置你可以嘗試下能解決你的問題。

 

https://www.ossez.com/t/junit-5-spring-junit-vintage/562


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM