
Discover how test containers support integration tests within the test pyramid, as a community-driven, MIT-licensed library for daily practical use.
Testcontainers address the limits of mocks and in-memory databases by providing production-like, containerized databases for integration tests, delivering closer compatibility with real systems and more reliable end-to-end coverage.
Discover how test containers replace mocks with dockerized external dependencies in integration tests. Configure databases, rest services, and Kafka as containers to catch bugs earlier and improve software quality.
Ensure your testing environment meets system requirements, with Docker available and a running Docker daemon; use Docker version 1709 or newer, noting platform limits on Mac, Windows, and CI environments.
Identify tooling—the test containers jar from Maven Central—and pair it with a test framework (JUnit 4/5 or Spock) and a build tool (Maven or Gradle) with Java runtime and JDK.
Explore the first testcontainers example by starting a Docker container from a JUnit test, using a Maven simple project archetype, Java 11 compatibility, and JUnit 5.9.0 with Testcontainers 1.17.3.
Explore how test containers integrate with JUnit 5 to automatically start and stop a container before and after each test method.
Integrate test containers with JUnit 4 by adjusting dependencies, using JUnit 4 rules, and ensuring public test classes, methods, and rules; switch between JUnit 4 and 5 as needed.
Configure logging for test containers using logback and slf4j, set up a test XML, adjust log levels to reveal container startup and docker communication details for debugging.
Explore port mapping with docker and test containers, exposing postgres 5432 ports, retrieving mapped host ports with getMappedPort, and testing a task list service via spring jdbc template.
Learn how to pass environment variables to a Postgres container with Testcontainers, configuring the user, password, and database name to initialize and test a task list service.
Mount a database init script into a Postgres container using test containers, mapping a classpath resource to the container path in read-only mode, enabling data insertion during tests.
Learn how to access test containers logs by snapshotting container logs or streaming them with callbacks, using two string consumers and a waiting consumer, and retrieving logs via get locks.
Learn how test containers determine container liveness by pinging the host port, using wait strategies, and combining lock message and health checks for reliable test setup.
Explore readiness and liveness checks in test containers, showing how Docker container inspect verifies running state and how various startup check strategies control when tests start.
Define container dependencies to start multiple containers in a strict order instead of parallel, ensuring RabbitMQ or Kafka components initialize before test drivers, with PostgreSQL and engines starting per dependencies.
Create docker images on the fly from a docker file using test containers, and spin up a Postgres 14 container for integration testing.
Explore how testcontainers pulls docker images and substitutes image names to bypass docker hub rate limits by using a prefix via environment variable or testcontainers.properties, ensuring your repository hosts images.
Learn to use docker compose within tests by running multiple services with a testcontainers docker compose container, exposing service ports and obtaining host and port dynamically.
Explore test containers modules that simplify docker container definitions with a convenient API, using the Postgres module to run a JDBC Postgres container and expose ports with minimal configuration.
Explore running tests inside docker containers with test containers, configuring maven and OpenJDK 11, mounting volumes and docker socket, and resolving docker host networking for ci environments.
Explore how to integrate and use test containers in real-world integration testing, guided by your feedback and real-world examples.
Learn how to run integration tests for a Spring Boot app with test containers, swapping H2 for MySQL and using dynamic JDBC URLs and test properties to ensure production-like schemas.
Learn how to perform Node.js integration tests with Testcontainers, connecting Express with Redis and Bull queues, including running Redis in Docker and testing REST APIs.
Why should you learn about Testcontainers, and what is it at all? If you reached here, you'll surely have an idea about that. I suppose you're testing your software already and want to figure out what Testcontainers can exactly do for you to somehow improve the quality of testing.
So welcome here to the first course on Udemy regarding that topic. I'm Ansgar, and I'm a freelanced software engineer, working with tools like Testcontainers almost every day.
Testcontainers points out, that it makes testing - especially integration testing - easier. I totally agree, but there are other - relevant and important - aspects which should be mentioned. Here are only a few examples:
It makes extension of your integration tests scope to the outermost boundaries possible without having to switch to full-fledged e2e tests
You can avoid having potentially confusing test setup with mocks and fakes
Using H2 although that's likely not your production database? No longer soon, perhaps ...
Not relying on JPA but on plain SQL and want to test your statements against a production-like database system? Easy with Testcontainers!
Using Docker in your build lifecycle already? Then setting up Testcontainers is in a breeze
...
In this course, I'll talk about the above-mentioned topics and give you a step-by-step walkthrough of the most important features of Testcontainers. For this, I'll stick to the following guidelines:
This course is about practice, not primarily theory (theory of testing for example)
I keep sections short and try my best to get to the point quickly in order to accelerate your progress. If a question stays open: Leave me a message
Feedback and discussions are always welcome. I plan to extend this course content on demand based on your feedback
Ready for takeoff? Subscribe to the course and let's go right away.