第一步:检查注解
检查是否有如下注解
@RunWith(SpringRunner.class)
@SpringBootTest
如果没有,添加依赖并补充注解
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
第二步:
作用:Spring Boot会自动根据你jar包的依赖来自动配置项目。
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})

本文介绍了SpringBoot项目中重要的注解@RunWith(SpringRunner.class)和@SpringBootTest的使用,以及如何添加JUnit测试依赖。通过@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}

被折叠的 条评论
为什么被折叠?



