最近在看《代码整洁之道》《重构》这两本书
里面都着重的提到过,单元测试
说来惭愧以前的测试也是应付上级检查,所以对这块的认知并不足够
但要成为一名合格的开发者,还是应该把这一块捡起来
@Test
是最简单的了,没啥好说的
快速生成测试类 https://blog.csdn.net/jj_nan/article/details/64134781
基于RestTemplate测试http接口
https://blog.csdn.net/dounine/article/details/72953463
类似的HTTP客户端有Unirest、feign等
最简单的是加俩注解
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = 启动类Application.class)
但确定很明显,需要启动整个项目,限制太多了
这个时候就需要使用mock的形式
JMockit中文网 http://jmockit.cn/index.htm(教程简单易懂,非常推荐)
Mockit
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>