Skip to content
Fresh

Run tests

Back

Guides

Testing REST API integrations using WireMock

Learn how to create a Spring Boot application that integrates with external REST APIs, then test those integrations using Testcontainers and WireMock.

Java Testing with Docker

20 minutes

1

Create the project

2

Write tests

3

Run tests

« Back to all guides

Run tests and next steps

Copy as Markdown

Open MarkdownAsk Docs AIClaudeOpen in Claude

Table of contents


Run the tests

console
$ ./mvnw test

Or with Gradle:

console
$ ./gradlew test

You should see the WireMock Docker container start in the console output. It acts as the photo service, serving mock responses based on the configured expectations. All tests should pass.

Summary

You built a Spring Boot application that integrates with an external REST API, then tested that integration using three different approaches:

  • WireMock JUnit 5 extension with inline stubs
  • WireMock JUnit 5 extension with JSON mapping files
  • Testcontainers WireMock module running WireMock in a Docker container

Testing at the HTTP protocol level instead of mocking Java methods lets you catch serialization issues and simulate realistic failure scenarios.

To learn more about Testcontainers, visit the Testcontainers overview.

Further reading