Syakur Rahman
Syakur Rahman

Reputation: 2102

Spring Test Module vs Mockito

I am learning about integration testing a spring app that communicates with a rest API. I found out from this article that spring test supports two ways to do, what I assume the same thing.

  1. Create a mockserver using MockRestServiceServer
  2. Create a mock object using Mockito

I understand that the former intercepts http request; then returns the objects, while the latter returns the object directly without bothering with any http requests at all. Since in the end, at least in most cases, we just verify the object retrieved and compare it to the expected result.

So, my Questions; if try to compare:

  1. What are possible trade-offs; if I choose either one of them?

  2. Are there any advantages of choosing one than the other?

  3. For which cases would I prefer one compared to the other (possible use cases of each)?

Upvotes: 4

Views: 397

Answers (1)

Erlan
Erlan

Reputation: 2088

Mockito mocks out all internal part of restTemplate and just returns responses to method directly.

MockRestServiceServer lets restTemplate to run all the things before httpClient call.

It means you will test error handling, mapping etc with MockRestServiceServer.

Upvotes: 2

Related Questions