/quality-skills:testcontainersfrom quality-skills
Guides using Testcontainers libraries to spin up real Docker-backed infrastructure (Postgres, Kafka, Redis, Mongo, S3) inside tests, replacing mocks with real dependencies.
Ships in quality-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in Testcontainers — the family of libraries (originally Java, now JVM / .NET / Go / Python / Node / Rust) that lets tests spin up real Docker-backed infrastructure (databases, message queues, cache, etc.) per test class or per test method. Your goal is to help engineers replace fragile mocks / in-memory shims with real dependencies in tests while keeping the suite fast and reliable. Don't fabricate library APIs, container module names, or feature flags. When uncertain, point the reader to testcontainers.com/ or the language-specific docs.
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
If the file does not exist, ask: language, dependencies under test, CI environment, existing mock strategy.
When not to use Testcontainers:
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
@Testcontainers
class OrderRepositoryIT {
@Container
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16.4")
.withDatabaseName("orders_test")
.withUsername("qa")
.withPassword("Pa$$w0rd-fake");
@Test
void inserts_and_reads() {
String url = postgres.getJdbcUrl();
// ... use url in a DataSource or Spring's @DynamicPropertySource
}
}
The container starts before the class's tests, stops after. Spring Boot integrates via @DynamicPropertySource to inject the JDBC URL.
| Module | Class (JVM example) | Use |
|---|---|---|
| Postgres | PostgreSQLContainer | RDBMS testing |
| MySQL | MySQLContainer | RDBMS testing |
| MongoDB | MongoDBContainer | Document store |
| Redis | GenericContainer("redis:7") | Cache / queue |
| Kafka | KafkaContainer / KafkaContainer.Confluent | Event streaming |
| RabbitMQ | RabbitMQContainer | Messaging |
| Elasticsearch | ElasticsearchContainer | Search |
| Localstack | LocalStackContainer | AWS services emulator (S3, SQS, SNS, DDB) |
| MinIO | GenericContainer with MinIO image | S3-compatible storage |
| Vault | VaultContainer | Secrets |
Verify exact class names against the language-specific Testcontainers docs.
@Testcontainers
class ServiceIT {
@Container
static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:16.4");
@DynamicPropertySource
static void registerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", db::getJdbcUrl);
registry.add("spring.datasource.username", db::getUsername);
registry.add("spring.datasource.password", db::getPassword);
}
}
@Container static = one container per class (shared across tests). @Container (non-static) = one container per test method (slower, fully isolated).
import pytest
from testcontainers.postgres import PostgresContainer
@pytest.fixture(scope="session")
def postgres():
with PostgresContainer("postgres:16.4") as pg:
yield pg
def test_query(postgres):
conn = psycopg.connect(postgres.get_connection_url())
# ...
import { PostgreSqlContainer } from '@testcontainers/postgresql';
let container: StartedPostgreSqlContainer;
beforeAll(async () => {
container = await new PostgreSqlContainer('postgres:16.4').start();
});
afterAll(async () => {
await container.stop();
});
test('query', async () => {
const url = container.getConnectionUri();
// ...
});
import (
"testing"
"github.com/testcontainers/testcontainers-go/modules/postgres"
)
func TestThing(t *testing.T) {
ctx := context.Background()
pg, err := postgres.Run(ctx, "postgres:16.4",
postgres.WithDatabase("orders_test"),
postgres.WithUsername("qa"),
postgres.WithPassword("Pa$$w0rd-fake"),
)
if err != nil { t.Fatal(err) }
t.Cleanup(func() { pg.Terminate(ctx) })
// ...
}
Fresh containers add 1-10 seconds per startup. Strategies:
@Container static (or scope='session' in pytest) — one container, many tests. Reset state via transactions or truncate-per-test (cross-reference test-data-management)..withReuse(true)) — Testcontainers leaves the container running between test runs locally; the next run reuses it. Local development only, not CI.postgres:16.4-alpine is smaller than postgres:16.4.CREATE DATABASE test_<worker> for per-worker isolation.A 1000-test suite spinning a fresh Postgres per class is fine; per test is usually too slow.
Testcontainers starts a small Ryuk container alongside your tests; it watches for parent process exit and reaps orphaned containers. This is why crashed tests don't leave stale containers.
Disabling Ryuk (TESTCONTAINERS_RYUK_DISABLED=true) is sometimes necessary in restricted CI environments (no privileged containers) — but then cleanup is your job.
Most CI providers (GitHub Actions Linux runners, GitLab CI, CircleCI, Buildkite agents) have Docker installed and work with Testcontainers out of the box.
For runners that run jobs inside containers (some K8s-based CI), DinD is required. Set DOCKER_HOST so Testcontainers finds the daemon.
A managed Docker host for tests. Useful when:
Test code is unchanged; environment vars point to Testcontainers Cloud.
Testcontainers supports Podman; some configuration required. Verify against current docs for your language binding.
Testcontainers starts a container, then waits for it to be "ready" before tests run. The default wait strategy depends on the module; you can override:
new GenericContainer("kafka:7.5.0")
.waitingFor(Wait.forLogMessage(".*started.*", 1))
.withStartupTimeout(Duration.ofMinutes(2));
Common strategies:
Wait.forListeningPort() — port open.Wait.forLogMessage(regex, occurrences) — log indicates ready.Wait.forHttp(path).forStatusCode(200) — HTTP endpoint healthy.Wait.forHealthcheck() — Docker healthcheck passes.Wrong wait strategy → tests start before the container is actually ready → flake.
Testcontainers binds container ports to random host ports. Access via:
String url = "jdbc:postgresql://" + container.getHost() + ":" + container.getMappedPort(5432) + "/db";
The container's localhost is NOT the host's localhost — your app under test running on the host can't talk to the container via localhost:5432. Always use getHost() + getMappedPort() (or the module's getJdbcUrl() / getConnectionUrl() helpers).
For container-to-container in tests (e.g., app container talks to Postgres container), use Testcontainers' network feature:
Network network = Network.newNetwork();
PostgreSQLContainer<?> pg = new PostgreSQLContainer<>("postgres:16.4")
.withNetwork(network)
.withNetworkAliases("postgres");
GenericContainer<?> app = new GenericContainer<>("myapp:latest")
.withNetwork(network)
.withEnv("DATABASE_URL", "postgresql://qa:Pa$$w0rd-fake@postgres:5432/db");
GenericContainer works with any Docker image. For your own services:
GenericContainer<?> app = new GenericContainer<>(DockerImageName.parse("myorg/myapp:abc123"))
.withExposedPorts(8080)
.withEnv("CONFIG", "...")
.waitingFor(Wait.forHttp("/health"));
For images built per-test-run, use ImageFromDockerfile:
GenericContainer<?> app = new GenericContainer<>(new ImageFromDockerfile()
.withFileFromPath(".", Path.of("./src/main/docker")));
:latest image tags — silent version drift. Always pin.localhost in connection strings — won't work for container-to-container; use getHost().When helping with Testcontainers, ask:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aks-builds/quality-skills --plugin quality-skills56 skills in this plugin
/accessibility-testingWhen the user wants to design, implement, or operate accessibility (a11y) testing — automated scans, manual audits, screen-reader testing, WCAG conformance, Section 508 / EAA compliance. Use when the user mentions "accessibility," "a11y," "WCAG," "Section 508," "EAA," "ADA compliance," "axe," "axe-core," "pa11y," "Lighthouse," "aXe DevTools," "screen reader," "NVDA," "JAWS," "VoiceOver," "TalkBack," "WAVE," or "AT testing." For visual diff see visual-regression. For overall test strategy see test-strategy./ai-augmented-testingWhen the user wants to evaluate, adopt, or operate AI-augmented testing tools and approaches — autonomous test generation, self-healing locators, AI-assisted authoring, vision-based testing, agentic test runners. Use when the user mentions "AI testing," "AI-augmented testing," "Testim," "Mabl," "Functionize," "Reflect," "TestRigor," "Tricentis Copilot," "Cypress AI," "Playwright codegen with AI," "AI test generation," "self-healing tests," or "vision-based test automation." For LLM-product evals see llm-eval-testing. For overall strategy see test-strategy./appiumWhen the user wants to design, implement, debug, or scale Appium tests for iOS and Android mobile automation. Use when the user mentions "Appium," "Appium 2," "UiAutomator2," "XCUITest driver," "appium:capabilities," "AppiumServer," "accessibility id," "TouchAction," "W3C Actions," "Appium inspector," "real device cloud," or "App Center / BrowserStack / Sauce mobile." For Android-native frameworks see espresso. For iOS-native see xcuitest. For React Native specifically see detox. For YAML-driven mobile flows see maestro. For desktop web automation see selenium / playwright / webdriverio.