從 Spring Boot 2.4.0 的測試引擎已經使用 Junit 5 的測試了。
因此測試引擎不再需要 exclude junit-vintage 到 Spring Boot 的測試依賴了。
2.4.0 的測試實例應該使用下面的依賴配置:
<!-- TESTS -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
這個問題在 2.3.3 的版本出現了上面的問題,有關這個問題的描述和解決方法,請參考:JUnit 5 測試 Spring 引擎的時候提示 junit-vintage 錯誤
中的內容。
測試引擎 junit-vintage 主要是版本兼容性的問題。