Calling APIs is business as usual. Building API clients is always good fun, testing them is somewhat trickier.

Wiremock is one of the most frequently used tools to mock APIs. Setting it up for testing purposes in your Spring Boot application is a bit daunting. Or should I say: WAS daunting. Enter WireMock Spring Boot, making your life easier.

I’ll kick off with building a simple API client and adding WireMock Spring Boot in the mix. Although simple, there are some gotchas as usual.

As a wrap-up, we’ll go for some practical tips on how to test a third-party client. Expect some tips on how to figure out what calls are done and how to turn this in some nice tests.

Devoxx Belgium

General info

Offline questions and remarks

Why invest time in Wiremock if you have testcontainers?

Indeed, why mock when you can have the real thing, right? Here are some reasons why you still want to invest in Wiremock

  1. Testcontainers are only available from Spring Boot 3.1. If you are working on an older application, then chances are that you haven’t upgraded to the latest and greatest. Wiremock is a great alternative then
  2. Your build infrastructure might not support testcontainers, not have enough resources to run containers, or this functionality is just not available during build time.
  3. Wiremock also helps while developing locally, not only during testing. It’s also easy to startup and does not require a lot of resources

Do you need wiremock for unittesting when the tester/QA engineer/… is using mocks?

Using mocks for unittests does not exclude your tester from using mocks as well, these are not mutually exclusive.

Unittests focus on checking if the implemented business logic works as expected. A QA engineer tests real life scenarios, and your code might be a part of that (Integration test if you like). If there are multiple scenarios, then you need to mock these situations with the appropriate data/responses.

Wiremock studio discontinued

Although useful, it is not encouraged to use Wiremock studio. Oleg Nenashev from the wiremock project says:

This proprietary product has been discontinued for more than one year, and the recent security advisory announce a severe security issue that will not be fixed.

If you want something more visually to deal with the admin API, you can always import the open API specs in postman or insomnia.


youtube recording