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);
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,
})
RedisContainer redisContainer = new RedisBuilder().Build();
await redisContainer.StartAsync();
const redis = await new GenericContainer("redis:5.0.3-alpine")
.withExposedPorts(6379)
.withWaitStrategy(Wait.forLogMessage("Ready to accept connections"))
.start();
redis = (
DockerContainer("redis:5.0.3-alpine")
.with_exposed_ports(6379)
)
redis.start()
wait_for_logs(redis, "Ready to accept connections")
let docker = clients::Cli::default();
let redis = docker.run(redis::Redis::default());
redis <-
run $
containerRequest (TestContainers.fromTag "redis:5.0.3-alpine")
& setExpose ["6379/tcp"]
& setWaitingFor (waitUntilMappedPortReachable "6379/tcp")
redis = Testcontainers::DockerContainer.new("redis:5.0.3-alpine").with_exposed_port(6379)
redis.start
(def container (-> (tc/create {:image-name "redis:5.0.3-alpine")
:exposed-ports [6379]})
(tc/start!)))
{:ok, _} = Testcontainers.start_link()
config = %Testcontainers.Container{image: "redis:5.0.3-alpine"}
{:ok, container} = Testcontainers.start_container(config)
Modules
Test Anything You Can Containerize: Database, Message Broker, And More
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.
A huge thankyou to our sponsors
Bronze Sponsors
Donors
Backers
Community Champions
Inspirational members of the community
Testcontainers Community Champions actively contribute to the growth and betterment of the Testcontainers community. They are passionate about Testcontainer, and use their knowledge and skills to help others succeed.
Meet our Community Champions










