java-testcontainers
Installation
SKILL.md
Java Testcontainers (2.x)
Run real dependencies (databases, brokers, caches) in Docker for integration tests. This skill is framework-neutral. If the project uses Spring Boot and the spring-boot-testing skill is installed, use it for @ServiceConnection, @DynamicPropertySource and test slices; for Quarkus, rely on Dev Services (Quarkus skills/docs), not hand-wired containers.
Workflow
- Detect the existing version (
pom.xml/build.gradle) and test framework (JUnit Jupiter). Testcontainers 2.x has no JUnit 4 support. - Pick the smallest container that matches production (same DB engine and major version; never H2 as a stand-in for behavior you care about).
- Choose a lifecycle (table below), configure waiting, wire connection details into the code under test.
- Run locally and in CI; check Docker availability and speed.
Testcontainers 2.x essentials
- Artifacts are all prefixed
testcontainers-:org.testcontainers:testcontainers-junit-jupiter,testcontainers-postgresql,testcontainers-mysql,testcontainers-kafka, etc. (1.x:junit-jupiter,postgresql). Core staysorg.testcontainers:testcontainers. - Module container classes moved to per-module packages, e.g.
org.testcontainers.postgresql.PostgreSQLContainer(1.x:org.testcontainers.containers.PostgreSQLContainer). Core classes (GenericContainer,Network,wait.strategy.*) remain underorg.testcontainers.containers. - Module container classes are no longer generic:
PostgreSQLContainer, notPostgreSQLContainer<?>. - Use a BOM to keep versions aligned:
org.testcontainers:testcontainers-bom:2.0.5(verify the current release on Maven Central). - Docker Compose: use
ComposeContainer(Compose v2);DockerComposeContaineris still present in 2.0.5 (older API); preferComposeContainer.