目录
前言
写好的service层代码,不想启动程序再用postman工具进行接口测试,有没有更好的办法去测试?单元测试可以做到,本文主要介绍单元测试的方法,以及涉及到数据库操作时的回滚操作方法。
环境配置
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
单元测试注解介绍
需要用到的注解
下面这篇博客写的不错
SpringBoot Test及注解详解 - codedot - 博客园 (cnblogs.com)
@SpringBootTest
@RunWith(SpringRunner.class)
@Resource、@Autowired 下面这篇博主写得不错,推荐阅读。