Appearance
Fresh
Run tests
Back
Testing a Spring Boot REST API with Testcontainers
Learn how to create a Spring Boot REST API with Spring Data JPA and PostgreSQL, then test it using Testcontainers and REST Assured.
Java Testing with Docker
25 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 Postgres Docker container start and all tests pass. After the tests finish, the container stops and is removed automatically.
Summary
The Testcontainers library helps you write integration tests by using the same type of database (Postgres) that you use in production, instead of mocks or in-memory databases. Because you test against real services, you're free to refactor code and still verify that the application works as expected.
To learn more about Testcontainers, visit the Testcontainers overview.