我已经从Spring迁移到了Spring-boot版本2.6.2。mvn干净安装成功了,但是没有junit(版本4.12)在执行。经过一些研究,我知道Spring-boot 2.4以后,JUnit 4已经被删除了。我尝试了以下解决方案,但没有成功。
After updating to latest Spring boot version, spring-boot-starter-parent 2.6.2, my tests stop executing
Spring Boot maven unit tests not being executed
4条答案
按热度按时间lsmepo6l1#
JUnit 5 = JUnit平台+ JUnit Jupiter + JUnit版本。
请参阅:Junit 5文档
如果你通过依赖最新的spring-boot-starter-test来导入junit-jupiter,它将只运行Junit 5风格的测试用例。所以Junit提供了junit-vintage来运行旧的Junit 3/Junit 4用例,默认情况下它不包含在spring-boot-starter-test依赖项中。所以有两个解决方案来保持Junit 4的运行:
1.依赖于junit-jupiter和junit-vintage来支持所有junit 3/4/5的情况。
1.从spring-boot-starter-test中排除junit-jupiter以运行Junit 4
zi8p0yeb2#
从spring-boot-starter-test依赖项中排除junit-jupiter-engine和junit-vintage-engine,然后在pom中添加JUnit 4依赖项:
u91tlkcl3#
我认为您应该迁移到JUnit 5。
sxissh064#
从SpringBoot V2.2开始,Spring默认只支持JUnit 5,并删除了与JUnit 4的向后兼容性。在Spring 2.2发行说明中明确指出:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes
“您不能使用junit-vintage-engine,并且需要显式回滚到JUnit 4:“
Springboot 2.4发行说明提到了POM依赖项的更改:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Release-Notes#junit-5s-vintage-engine-removed-from-spring-boot-starter-test