SpringBoot单元测试

2019-03-19  本文已影响0人  zhanghanga

springboot 中有专门的组件来做单元测试:
第一步,在pom中新增依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
第二步,新建UserTest放置在test目录下:

@SpringBootTest(classes = {App.class})
@RunWith(SpringRunner.class)
public class UserTest {
@Resource
private UsersMapper usersMapper;
@Test
public void testAdd() {
Users user = new Users() ;
user.setPasswd("123");
user.setUsername("enjoy");
usersMapper.insertSelective(user);
}
@Test
public void testFindUser() {
Users enjoy = usersMapper.findByUsernameAndPasswd("enjoy", "123");
System.out.println(enjoy);
}
}

这样SpringBoot集成单元测试成功!

上一篇下一篇

猜你喜欢

热点阅读