Skip to content
Fresh

Run tests

Back

Guides

Securing Spring Boot microservice using Keycloak and Testcontainers

Learn how to create an OAuth 2.0 Resource Server using Spring Boot, secure API endpoints with Keycloak, and test the application using the Testcontainers Keycloak module.

Java Testing with Docker

30 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 Keycloak and PostgreSQL Docker containers start with the realm settings imported and the tests pass. After the tests finish, the containers stop and are removed automatically.

Summary

The Testcontainers Keycloak module lets you develop and test applications using a real Keycloak server instead of mocks. Testing against a real OAuth 2.0 provider that mirrors your production setup gives you more confidence in your security configuration and token-based authentication flows.

To learn more about Testcontainers, visit the Testcontainers overview.

Further reading