为什么我们应该使用 wiremock 而不是 Mockito

Why we should use wiremock instead of Mockito

我有 Restclient class 每当在 Restclient 对象上调用 GET 方法时,它都会对 URL 进行休息调用。我有一个正确的逻辑在背后工作。

现在考虑一个案例,而不是使用 wiremock 我使用 Mockito 模拟 Restclient 对象上的方法 GET 以 return 适当的响应。

这是否有缺点,例如主模块涵盖的代码量还是两者都同样好?

Wiremock 为基于 HTTP 的 API 提供模拟器,而 Mockito 提供 method/object.

的模拟实现

If we are using Mockito to mock HTTP-based method, it means we are trying to return the object/response without testing any code to invoke REST service, getting HTTP response and deserializing the same.

如果我们使用 Wiremock,我们将能够进行接近实际的测试,因为它将测试 REST 调用的调用以及响应的反序列化。

https://www.linkedin.com/pulse/what-difference-between-stub-mock-virtual-service-wojciech-bulaty/ 是一篇值得阅读的好文章,当然不是我写的:-)