SpringBoot junit单元测试
来源:互联网 发布:cin2男士内裤 知乎 编辑:程序博客网 时间:2024/05/18 02:01
SpringBoot项目的快速搭建可参考:构建SpringBoot项目 (分为两部分:第一部分是project的基本信息,根据当前开发环境选择;第二部是扩展部分,添加不同的jar包支持。生成项目之后直接导入本地开发工具即可)。
SpringBoot 支持junit单元测试,编写测试类之前需要添加spring-boot-starter-test 依赖,如果构建项目时已添加直接忽略这一步,pom中添加依赖:
<!-- 单元测试jar --> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope> </dependency>接下来新建测试类TestFileInfoService:
@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) public class TestFileInfoService { @Autowired private FileInfoService fileInfoService; @Test public void TestGetFileList() { List<FileVO> list = fileInfoService.getFileList(); Assert.assertTrue(list.size() == 4); } }@RunWith :SpringJunit支持
@SpringBootTest : SpringBoot启动支持,Application为工程的启动类
Junit的基本注解和用法在这里基本上都支持,配置文件的属性值可以直接用@Value注解获取,例如:
@Value("${spring.mail.username}") private String from;
为测试类添加@RunWith和@SpringBootTest两个注解之后就可以进行Junit测试了,这样可以在不用编写controller类的情况下进行业务逻辑的测试。
阅读全文
0 0
- SpringBoot Junit单元测试
- SpringBoot junit单元测试
- SpringBoot的Junit单元测试
- SpringBoot 使用JUnit 单元测试
- springboot第二天 junit单元测试
- SpringBoot开发Junit单元测试方法
- SpringBoot与JUnit+Mockito 单元测试
- SpringBoot框架下基于Junit的单元测试
- SpringBoot 学习记录(三)- Junit 单元测试
- SpringBoot-JUnit
- JUnit单元测试
- JUnit 单元测试
- 单元测试JUnit
- Junit单元测试
- Junit单元测试
- junit单元测试
- JUnit单元测试
- Junit单元测试
- win7 64位操作系统 VS2015下配置OpenCV3.2.0教程
- Python全栈之路系列之正则表达式re模块
- 配置环境变量
- ApplicationContextAware接口的作用
- 跳转控制语句break,continue,return的区别。
- SpringBoot junit单元测试
- ELK 接入日志数据配置参考
- ECharts介绍入门
- JAVA学习笔记
- 进程的优先级
- 【HTTP header】【Access-Control-Allow-Credentials】跨域Ajax请求时是否带Cookie的设置
- 使用libvirt的networkfilter对网络进行过滤
- Oracle SQL语句面试题一
- 安卓 6.0检查权限以及请求权限