是不是报错
TestEngine with ID ‘junit-vintage‘ failed to discover tests
junit-vintage-engine 是 JUnit 4 中使用的测试引擎。
junit-jupiter-engine 是 JUnit 5 中使用的测试引擎。
import org.junit.Test; //我是4
import org.junit.jupiter.api.Test ; //这里是5
springboot 2.1 之前
使用 junit5 需要配合@ExtendWith(SpringExtension.class)才能正常工作的
springboot 2.1 .*
2.1之后的版本 @SpringBootTest 的已经组合了@ExtendWith(SpringExtension.class),因此,无需在进行该注解的使用了,进一步简化。
springboot <2.4
2.4之前要用junit5,需要去除junit-vintage-engine
(如果报estEngine with ID ‘junit-vintage’ failed to discover tests)
<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>
springboot >2.4
默认JUnit5,如果要用4,需要加junit包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.3.12.RELEASE</version>
<scope>test</scope>
</dependency>
的时候可以用@RunWith(SpringRunner.class)
如果版本大于2.4,则必须配置junit,否则无法使用@RunWith(SpringRunner.class)和org.junit.Assert.*
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>