Unit tests with real dependencies

Testcontainers is an open source framework for providing throwaway, lightweight instances of databases, message brokers, web browsers, or just about anything that can run in a Docker container.
How it works

Test dependencies as code

No more need for mocks or complicated environment configurations. Define your test dependencies as code, then simply run your tests and containers will be created and then deleted.

With support for many languages and testing frameworks, all you need is Docker.

GenericContainer redis = new GenericContainer("redis:5.0.3-alpine")
    .withExposedPorts(6379);
req := testcontainers.ContainerRequest{
  Image:        "redis:latest",
  ExposedPorts: []string{"6379/tcp"},
  WaitingFor:   wait.ForLog("Ready to accept connections"),
}
await new TestcontainersBuilder<TestcontainersContainer>()
  .WithImage("alpine")
  .WithEntrypoint("top")
  .Build()
  .StartAsync()
  .ConfigureAwait(false);
with PostgresContainer("postgres:9.5") as postgres:
  e = sqlalchemy.create_engine(postgres.get_connection_url())
  result = e.execute("select version()")
const { GenericContainer } = require("testcontainers");
const container = await new GenericContainer("alpine")
  .withExposedPorts(22, 80, 443)
  .start();
let container = docker.run(MyImage::default());
Use cases

How Testcontainers can help you

Data access layer integration tests

Use a containerized instance of your database to test your data access layer code for complete compatibility, without requiring a complex setup on developer machines. Trust that your tests will always start with a known state.

UI/Acceptance tests

Use containerized web browsers, compatible with Selenium, to run automated UI tests. Each test gets a fresh, clean instance of the browser, without having to worry about variations in plugins or required updates.

Application integration tests

Run your application in a short-lived test mode with dependencies, such as databases, message queues or web servers, to give you a rich interactive and explorative testing environment.
Get started

Supported Languages

There are implementations of Testcontainers in all of your favorite languages. Click through to read their specific documentation.
Industry standard

Companies using Testcontainers

Spotify JetBrains Netflix Uber CapitalOne Elastic Wise Zalando Skyscanner Playtika