SpringBoot整合junit
SpringBoot整合junit
主要分为4步
- 添加依赖
- 创建测试类
- 在测试类上添加注解
- 在测试类注入测试对象
1:导入依赖包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope></dependency> |
2:创建测试类
3:在测试类上添加注解并注入测试对象
测试类上注解:
@RunWith(SpringRunner.class)@SpringBootTest(classes = Springbootdemo1Application.class)
package com.offcn.springbootdemo1;import com.offcn.springbootdemo1.mapper.UUserMapper;import com.offcn.springbootdemo1.pojo.UUser;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;import javax.annotation.Resource;import java.util.List;//添加整合junit注解@RunWith(SpringRunner.class)@SpringBootTest(classes = Springbootdemo1Application.class)public class AppTest { //注入Mapper对象,用来获取List<UUser>集合 @Resource private UUserMapper userMapper; @Test public void TestMethod(){ List<UUser> uUsers = userMapper.selectUUser(); for (UUser uUser : uUsers) { System.out.println(uUser); } }} |
相关推荐
shirleypaddy 2020-10-19
qingmumu 2020-10-19
lustdevil 2020-10-18
ganlulululu 2020-10-12
lustdevil 2020-08-03
lustdevil 2020-07-18
lustdevil 2020-06-25
lustdevil 2020-06-21
zhengzf0 2020-06-21
宿命java 2020-06-15
JackYin 2020-06-14
dongxurr 2020-06-07
snowphy 2020-06-06
zhengzf0 2020-05-28
81901836 2020-05-26
Julywhj 2020-05-26