testcontainers
Skill2 starsChanged 4 months agoMITView on GitHub
Integration testing with Testcontainers: PostgreSQL, Redis, Kafka, RabbitMQ, localstack. Spin up real dependencies in Docker for reliable integration tests.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- aks-builds/quality-skillstheir own version, first seen Jun 12, 2026
- wshaddix/dotnet-skillstheir own version, first seen Feb 16, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- wshaddix/dotnet-skills★ 79same name
- aks-builds/quality-skills★ 5same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository45 other files it gives its agents.
- AGENTS.mdAGENTS.md
- allure-reportsSkill
- android-nativeSkill
- appian-lowcodeSkill
- appium-mobileSkill
- behave-bddSkill
- BiDiWave Cross-BrowserSkill
- BiDiWave Network InterceptionSkill
- CDPWave DebuggingSkill
- CDPWave TestingSkill
- db2-oracleSkill
- ebook-writerSkill
- flask-apiSkill
- flet-desktopSkill
- google-crawling-indexingSkill
- google-ranking-appearanceSkill
- google-seo-fundamentalsSkill
- google-seo-monitoringSkill
- jinja2-templatesSkill
- jmeter-load-testingSkill
- k6-load-testingSkill
- karate-api-testingSkill
- octane-almSkill
- paramiko-sshSkill
- postman-api-automationSkill
- prestashop-moduleSkill
- prompt-engineering-best-practicesSkill
- pytest-advancedSkill
- robot-frameworkSkill
- salesforce-devSkill
- sonarqube-quality-gatesSkill
- sql-serverSkill
- Skill NameSkill
- wave-ecosystem-guideSkill
- WaveXis AccessibilitySkill
- WaveXis CI/CD IntegrationSkill
- wavexis-cli-automationSkill
- wavexis-mcp-agent-integrationSkill
- WaveXis Network TestingSkill
- WaveXis Performance AuditSkill
- WaveXis Session RecordingSkill
- WaveXis Web ScrapingSkill
- webdriverioSkill
- wordpress-themesSkill
- xctest-iosSkill
The file
Files
Testcontainers
Integration testing with real dependencies via Docker containers.
1. Why Testcontainers
| Problem | Testcontainers Solution |
| In-memory DB ≠ production | Real PostgreSQL, Redis, MongoDB in Docker |
| H2 dialect differences | Same engine as production |
| Kafka mocks are incomplete | Real Kafka broker + topics |
| AWS testing is hard | Localstack S3, SQS, DynamoDB |
| Test isolation | Fresh container per test class / JVM |
2. Quick Start (Java + JUnit 5)
<!-- pom.xml -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>@Testcontainers
public class OrderRepositoryTest {
@Container
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:15-alpine")
.withDatabaseName("orders")
.withUsername("test")
.withPassword("test");
@DynamicPropertySource
static void props(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getPassword);
}
@Autowired OrderRepository repo;
@Test
void shouldSaveAndFindOrder() {
Order order = new Order("ORD-001", BigDecimal.valueOf(99.99));
repo.save(order);
assertThat(repo.findById("ORD-001")).isPresent();
}
}3. Container Types & Patterns
PostgreSQL
@Container
static PostgreSQLContainer<?> pg = new PostgreSQLContainer<>("postgres:15")
.withInitScript("schema.sql"); // Runs on startupRedis
@Container
static GenericContainer<?> redis = new GenericContainer<>("redis:7-alpine")
.withExposedPorts(6379);
@Bean
@Primary
RedisConnectionFactory redisFactory() {
return LettuceConnectionFactory.builder()
.host(redis.getHost())
.port(redis.getMappedPort(6379))
.build();
}Kafka
@Container
static KafkaContainer kafka = new KafkaContainer(
DockerImageName.parse("confluentinc/cp-kafka:7.5.0")
);
// Producer test
KafkaProducer<String, String> producer = new KafkaProducer<>(
Map.of(
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(),
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName(),
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()
)
);Localstack (AWS)
@Container
static LocalStackContainer localstack = new LocalStackContainer(
DockerImageName.parse("localstack/localstack:2.3")
).withServices(S3, SQS, DYNAMODB);
S3Client s3 = S3Client.builder()
.endpointOverride(localstack.getEndpointOverride(S3))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create("test", "test")
))
.region(Region.US_EAST_1)
.build();4. Python Testcontainers
# pytest + testcontainers
from testcontainers.postgres import PostgresContainer
import psycopg2
def test_postgres():
with PostgresContainer("postgres:15-alpine") as postgres:
conn = psycopg2.connect(postgres.get_connection_url())
cur = conn.cursor()
cur.execute("CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT)")
cur.execute("INSERT INTO users (name) VALUES ('Alice')")
conn.commit()
cur.execute("SELECT * FROM users")
assert cur.fetchone() == (1, "Alice")5. Lifecycle Optimization
| Strategy | Use Case | Speed |
| Per test class | Default, good isolation | Medium |
| Singleton container | Shared across suite | Fast |
| @RestartPerTest | Maximum isolation | Slow |
// Singleton (faster)
@Testcontainers
public class SharedDbTest {
@Container
static PostgreSQLContainer<?> pg = new PostgreSQLContainer<>("postgres:15");
// static = one container for all tests in class
}6. Docker Compose
@Container
static DockerComposeContainer<?> compose =
new DockerComposeContainer<>(new File("docker-compose.test.yml"))
.withExposedService("app", 8080)
.withExposedService("db", 5432);
String appHost = compose.getServiceHost("app", 8080);
int appPort = compose.getServicePort("app", 8080);7. CI/CD Requirements
- Docker daemon available (GitHub Actions
ubuntu-latesthas it) - Ryuk container cleanup enabled by default
- Mount
/var/run/docker.sockif running in Docker-in-Docker
# .github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with: { java-version: '21', distribution: 'temurin' }
- run: mvn test -Dtest='*Testcontainers*'8. Anti-Patterns
| Anti-Pattern | Fix |
| Using H2 in production, PG in tests | Use same DB in tests |
@Container on non-static field | Container restarts per test method |
| Hardcoding ports | Use getMappedPort() |
| No schema init | Use .withInitScript() or Flyway |
| Ignoring container logs | Enable log streaming for debugging |
9. Related Resources
- Skills:
sql-server,postgresql(if added),flask-api - Prompts:
generate-integration-test-suite(QA) - Agents:
test-architect
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

