Spring Boot 2.3.1单元测试@RunWith注解报错
问题:
在进行单元测试时,使用@RunWith(SpringRunner.class)注解,IDE报错:cannot resolve symbol ‘RunWith’。
解决方式一:
使用@ExtendWith(SpringExtension.class)即可
解决方式二:
若项目单元测试的依赖是默认导入的,则将pom.xml中单元测试的依赖配置:
<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>
更改为
<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>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
再Update一下Project就可以了。