VOOZH about

URL: https://thenewstack.io/what-is-testcontainers-and-why-should-you-care/

⇱ What Is Testcontainers, and Why Should You Care? - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-09-17 07:53:49
What Is Testcontainers, and Why Should You Care?
ato,contributed,
Containers / Software Testing

What Is Testcontainers, and Why Should You Care?

Testcontainers reduces friction in setting up and tearing down test environments, streamlining testing to enable more confident, robust development.
Sep 17th, 2024 7:53am by Kevin Wittek
👁 Featued image for: What Is Testcontainers, and Why Should You Care?
Featured image by Vedrana Filipović on Unsplash.
In modern software development, with its ongoing trend toward distributed system and microservice architectures with a big integration surface, writing software also means integrating with other systems. Integration tests are a great tool for ensuring the ongoing correctness of the system under test and for providing fast and constant feedback on the system’s behavior during the development cycle. Integration tests, however, often require external dependencies, such as databases, message brokers or web servers, all with their own idiosyncrasies on how to be configured and run correctly. Traditionally, managing these dependencies has been cumbersome, prone to inconsistencies and difficult to replicate across different machines. Historically this gave integration tests a bad reputation for being expensive to write and maintain. You either had to follow potentially outdated documentation to set up the environment in a laborious manual way (only to end up with a slightly broken environment) or use centrally maintained shared test environments that often resulted in test pollution. This is where Testcontainers comes in. My colleague Oleg Šelajev will be presenting this at All Things Open 2024, in a talk titled “Making your own Testcontainers module for fun and profit!

Meet Testcontainers

Testcontainers is an open source library for providing throwaway, lightweight instances of databases, message brokers, web browsers or just about anything that can run in a Docker container. By leveraging Docker to spin up lightweight, isolated instances of these services on demand and from within your codebase, Testcontainers solves the problem of environment management during testing and development. Testcontainers allows developers to create reliable and repeatable test and development environments with minimal effort in an Infrastructure as Code (IaC) method. It uses familiar languages for writing the production and test code and helping ensure that the code is tested against real, consistent services. This approach reduces the friction in setting up and tearing down test environments and makes tests more reliable and easier to maintain. For developers, Testcontainers is a game-changer, streamlining the testing process and enabling more confident, robust development.

Cleanup

Testcontainers also takes care of automatic cleanup of all Docker resources it creates, ensuring that your system remains free of clutter after tests are run. This cleanup process is seamlessly integrated with the test framework you are using, such as JUnit, where containers are automatically stopped and removed after the test execution. Additionally, Testcontainers relies on a specialized sidecar container called Ryuk, which monitors and ensures that all resources are properly cleaned up, even in cases where the test process might crash or terminate unexpectedly. By binding this cleanup process to the lifecycle of your test process and using Ryuk as a watchdog, Testcontainers guarantees that no stray containers, networks or volumes are left behind, keeping your environment clean and minimizing the risk of resource exhaustion or conflicts in subsequent test runs.

Modules

Testcontainers offers a rich set of modules that encapsulate best practices for using containers in the context of testing, making it even easier to integrate various technologies into your test suites. These modules are preconfigured Docker containers tailored for specific technologies, such as databases (e.g., PostgreSQL, MySQL), message brokers (e.g., Kafka, RabbitMQ) or even full-fledged application environments like Selenium for browser testing. By using these modules, developers can leverage tried-and-tested configurations that have been optimized for reliability and efficiency in testing scenarios. The Testcontainers modules catalog provides a comprehensive listing of available modules, allowing you to quickly find and implement the containerized services you need. Here are two minimal examples showcasing the same action both in Java and Go: How to define a Docker container using a Redis image, configuring its exposed port and starting the container in a way that will wait for the readiness of the Redis application within the container. In Java:
GenericContainer redis = new GenericContainer("redis:5.0.3-alpine")
 .withExposedPorts(379);
redis.start()

In Go:
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
 ContainerRequest: testcontainers.ContainerRequest{
 Image: "redis:5.0.3-alpine",
 ExposedPorts: []string{"6379/tcp"},
 WaitingFor: wait.ForLog("Ready to accept connections"),
 },
 Started: true,
})

Testcontainers Cloud

Besides these widely established open source libraries, Testcontainers offers a product to offload those containers seamlessly into the cloud, without requiring any changes to your Testcontainers code whatsoever: Testcontainers Cloud. By leveraging Testcontainers Cloud, you can significantly reduce the load on your local machine, freeing up resources for other tasks while still running complex, resource-intensive tests. 👁 Testcontainers Cloud overview.
This approach speeds up your development workflow and gives your testing environment architectural parity with the desired Docker runtime (e.g., x86) as the containers are executed in a consistent and scalable cloud environment. Whether you’re dealing with heavy workloads or simply want to streamline your testing process, Testcontainers Cloud provides a seamless integration that enhances both performance and reliability, allowing you to focus more on coding and less on managing local resources.

Wrapping Up

Testcontainers is a versatile and powerful tool that transforms how developers approach integration testing and local development. By providing an easy-to-use interface for spinning up Docker containers tailored to specific testing needs that is accessible straight from the familiarity of the utilized programming language, Testcontainers eliminates the common challenges associated with managing test environments. With modules that encapsulate best practices, automatic cleanup to keep your system tidy, and the ability to offload container execution to Testcontainers Cloud, this approach offers a comprehensive solution for maintaining consistency, reliability and efficiency in your testing processes. Whether you’re a developer looking to streamline your local workflow or a team aiming to scale your testing in the cloud, Testcontainers equips you with the tools necessary to ensure that your code works seamlessly across different environments. By adopting Testcontainers, you not only enhance the quality of your tests but also pave the way for a more robust and confident development cycle. Don’t miss our All Things Open 2024 session: Making your own Testcontainers module for fun and profit!

Learn More

TRENDING STORIES
Kevin Wittek is an engineering manager and Testcontainers OSS maintainer at Docker.
Read more from Kevin Wittek
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.