Real Dependencies with Testcontainers
Test against real databases in containers.
Why Testcontainers
Testcontainers runs real services — PostgreSQL, Redis, Kafka — inside Docker containers during tests.
You test against the real database, not an in-memory substitute, catching dialect and behavior differences.
Adding the Dependency
Add the Testcontainers JUnit and database modules to your build.
// build.gradle
testImplementation "org.testcontainers:junit-jupiter"
testImplementation "org.testcontainers:postgresql"All lessons in this course
- Unit Testing with JUnit and Mockito
- Web Layer Tests with MockMvc
- Integration Tests with @SpringBootTest
- Real Dependencies with Testcontainers