背景
- springboot框架搭建的项目。
- 已有的单测都使用junit4
- spring-boot-starter-test:2.3.0.release 下 junit-vintage-engine:5.6.2 下 junit:4.13.2
- 网上查阅资料:junit-vintage-engine 兼容junit4、junit5。
- 逐步升级 junit5:新写的单测用junit5,老单测保持 junit4。
- 但是,junit5写的单测,启动报错,内容如下:
解决
junit-vintage-engine 升级为 5.6.3,junit-jupiter 版本号保持一致,也升级5.6.3
<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>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--spring-boot-tarter-test 2.3.0 中的junit-vintage 5.6.2无法兼容junit4、junit5,升级5.6.3-->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.3</version>
</dependency>