Modern applications rely on multiple external systems — relational databases, messaging services, cloud APIs, and more. Unit tests alone can’t reliably validate these integrations.
Testcontainers has become the de-facto solution for running lightweight, disposable Docker containers directly from your JUnit 5 tests. This enables full integration testing without managing local databases or emulators manually.
In this post, walk you through a generic, reusable setup for:
✔ Spring Boot (3.x)
✔ JUnit 5
✔ PostgreSQL & Oracle containers
✔ Google Pub/Sub emulator
✔ Multi-datasource testing
✔ GitHub Actions or any CI environment
1️⃣ Why Testcontainers?
Testcontainers lets you spin up real infrastructure inside your tests:
-
Real PostgreSQL and Oracle Free instances
-
Real Pub/Sub emulator
-
Real networking
-
Real JDBC connections
All containers are created and torn down automatically → zero manual infrastructure.
It works on:
-
Docker Desktop
-
Podman on Windows (
podman machine start) -
Linux / macOS
2️⃣ Dependencies (pom.xml)
Add the core Testcontainers modules:
3️⃣ Test Profile (application-test.yml)
Create a fully isolated test profile:

No comments:
Post a Comment