【发布时间】:2018-11-25 13:00:52
【问题描述】:
我已经在 google 和 stackoverflow 中检查了 Spring Boot Rest API 的端到端测试。
我想立即测试控制器 -> 服务 -> 存储库。
我发现两种方法是有效的:
1. TestRestTemplate:
Single call to the controller method with in-memory database configuration for repository.
2. MockMvc:
Create 2 Test classes.
one for Controller->Service
and one for Service->Repository.
Is there any way to club both 2 classes into one class.
这是从上述两种方法对 Spring Boot Rest API 进行“端到端测试”的最佳方法???
【问题讨论】:
-
如果您想通过点击 http 端点来测试 APIS,请放心 (rest-assured.io) 可以考虑
-
搜索 REST API 的集成测试。您正在查看的内容是用于对服务的各个方面进行单元测试。如果您希望“一次完成所有事情”进行测试,那么集成测试就是它。
-
以上两种方法(TestRestTemplate、MockMvc)哪个是最好的?
标签: spring-boot junit spring-boot-test