概要:
- 演示如何从Controller层完成单个API的单元测试任务
- 单个API单元测试编写规范:一个Api对应一个测试类class,应尽可能包含Api调用会出现的状况
- 聚焦Controller的测试模板代码块讲解细化
- 涉及 Assertions , AssertJ 等Api的常规用法
- 先展示Controller层代码,再展示Tests代码,方便对照着查看
- Controller
/**
* @Description 家访Admin
* @Author blake
* @Date 2019-01-28 11:53
* @Version 1.0
*/
@Api(tags = "07. 家访管理", description = "家访详情、家访列表")
@RestController
@RequestMapping("/api/admin/home")
public class AdminHomeVisitController {
@Autowired
private AdminHomeVisitService adminHomeVisitService;
@ApiOperation(value = "家访列表", response = HomeVisitResponse.class, responseContainer = "List")
@GetMapping("/visits")
public Response listHomeVisit(HomeVisitSearchRequest request, Pageable pageable) {
return JsonSend.success(adminHomeVisitService.listHomeVisit(request, pageable));
}
@ApiOperation(value = "家访详情", response = HomeVisitResponse.class)
@GetMapping("/visit/{id}")
public Response getHomeVisitInfo(@PathVariable @ApiParam("家访id") Long id) {
return JsonS