Testcontainers Tutorial — Complete Guide to Java Integration Testing

A complete, hands-on Testcontainers tutorial series for Java developers. Master real integration testing with Spring Boot 3, JUnit 5, and actual infrastructure — PostgreSQL, Kafka, Redis, WireMock, LocalStack, and more.

Testcontainers Tutorial — Complete Guide to Java Integration Testing

This tutorial series takes you from zero to expert in Testcontainers and Java testing. Every article uses Spring Boot 3.3+, Testcontainers 1.20+, Java 21, and JUnit 5. All code examples are complete and runnable, following a real-world e-commerce order management domain throughout.

What you’ll build: A fully tested Spring Boot application — repositories tested against real PostgreSQL, Kafka consumers and producers tested against a real broker, REST clients tested with WireMock, AWS integrations tested with LocalStack, and a complete CI/CD setup with GitHub Actions.


Part 1: Foundations

  1. What Is Testcontainers and Why You Need It
  2. Setting Up Testcontainers in a Java Project
  3. JUnit 5 Integration — Lifecycle and Annotations
  4. Understanding Wait Strategies

Part 2: Database Testing

  1. PostgreSQL Testing with Testcontainers
  2. MySQL Testing with Testcontainers
  3. MongoDB and NoSQL Testing
  4. Database Migration Testing — Flyway and Liquibase

Part 3: Messaging and Streaming

  1. Kafka Integration Testing with Testcontainers
  2. RabbitMQ Testing with Testcontainers

Part 4: Caching and External Services

  1. Redis Testing with Testcontainers
  2. WireMock — Testing External REST APIs

Part 5: AWS and Security

  1. LocalStack — Testing AWS Services (S3, SQS, SNS)
  2. Keycloak and OAuth2 Testing with Testcontainers

Part 6: Testing Strategy

  1. Unit Testing vs Integration Testing vs System Testing in Java
  2. Spring Boot Testing Slices — @DataJpaTest, @WebMvcTest, and @SpringBootTest

Part 7: Advanced Patterns

  1. Singleton Containers and Shared Base Classes
  2. Container Reuse for Fast Feedback Loops
  3. Parallel Test Execution with Testcontainers

Part 8: Production and CI/CD

  1. Testcontainers in CI/CD — GitHub Actions, Docker, and Production Patterns