Spring Boot 的@RunWith注解无法使用

2,077 阅读1分钟

用idea自动生产的SpringBoot框架,版本为2.3.0,自动生成的xml文件中的junit测试依赖如下:

<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>

默认的exclusions这个标签的配置会导致test类上的RunWith注解无法使用,去掉即可。其实IDEA中Junit是无需这个注解的,会自动识别为runwith的环境配置,但是其他的ide工具不行,所以还是加上吧。