Appearance
Fresh
Run tests
Back
Testing REST API integrations using MockServer
Learn how to create a Spring Boot application that integrates with external REST APIs, then test those integrations using Testcontainers and MockServer.
Java Testing with Docker
20 minutes
Run tests and next steps
Copy as Markdown
Open MarkdownAsk Docs AIClaudeOpen in Claude
Table of contents
Run the tests
console
$ ./mvnw testOr with Gradle:
console
$ ./gradlew testYou should see the MockServer 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 using declarative HTTP clients, then tested that integration using the Testcontainers MockServer module. 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.