Spring Boot 的单元测试
引入依赖
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.5.2.RELEASE'
testCompile group: 'junit', name: 'junit', version: '4.12'
编写单元测试方法
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringSecurityApplication.class)
public class UserServiceTest {
@Autowired
private IUserService userService;
@Autowired
private UserRepository userRepository;
@Test
public void testService(){
User user = userService.findById(1L);
System.out.println(user);
}
@Test
public void testRepository(){
User user = userRepository.findOne(1L);
System.out.println(user);
}
}
就这么简单。
comtrol + alt + O:清理不必要的引入