springbootTest单元测试说明
目录
当pom.xml中引入的是
<dependencies> <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> </dependencies>
在单元测试中的测试类不需要写注解@RunWith(SpringRunner.class),
注解@SpringBootTest会帮我们引入@RunWith这个注解
当引入的测试包是这个依赖
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
测试类需要写@RunWith(SpringRunner.class)注解
如:
@SpringBootTest @RunWith(SpringRunner.class) public class RedisTemplateTests { }
注解@RunWith(SpringRunner.class)的使用场景是当测试类中需要使用spring容器中组件时,需要根据使用的测试包不同(上面两种方式)引入这个注解
本文来自博客园,作者:Lz_蚂蚱,转载请注明原文链接:https://www.cnblogs.com/leizia/p/16686804.html
分类:
SpringBoot1.5版本
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步