Skip to main content
skill GitHub Copilot official · GitHub

java-testcontainers — GitHub Copilot skill: setup and features

Helps write Java integration tests using Testcontainers 2.x and JUnit Jupiter with Docker dependencies. Useful when adding container tests or migrating from version 1.x.

Install into GitHub Copilot · Skills CLI (Vercel) All methods and platforms ↓
npx skills add github/awesome-copilot --skill java-testcontainers
Open on GitHub

What java-testcontainers does

This skill guides GitHub Copilot in generating framework-neutral integration tests in plain Java using Testcontainers 2.x. It enforces modern 2.x conventions, such as importing the org.testcontainers:testcontainers-bom:2.0.5 BOM, using prefixed artifacts like testcontainers-postgresql, and migrating away from generic container types like PostgreSQLContainer.

Inside are patterns for managing container lifecycles: static fields for per-class instances, singleton containers across test suites, and container reuse with withReuse(true). It warns against hardcoding host ports, pointing to dynamic resolution with getMappedPort and getHost, while configuring wait strategies and ComposeContainer.

Requirements include Docker, Podman or Colima, along with JUnit Jupiter, because Testcontainers 2.x drops JUnit 4 support completely. Skip this skill if your project uses Quarkus Dev Services, which manages test containers automatically without manual wiring.

What it helps with

  • migrate Java integration tests from Testcontainers 1.x to 2.x packages and artifacts
  • configure singleton container lifecycles to speed up test suites across classes
  • launch multi-container environments using ComposeContainer without fixed host ports
  • configure wait strategies and dynamic port resolution for GenericContainer

Example prompts for the agent

  • Write a JUnit Jupiter integration test for PostgreSQL using Testcontainers 2.x
  • Migrate our build.gradle Testcontainers dependencies to version 2.x using the BOM
  • Create a singleton Redis container setup shared across multiple test classes

How to install java-testcontainers

1Skills CLI (Vercel)

npx skills add github/awesome-copilot --skill java-testcontainers

2GitHub CLI

gh skill install github/awesome-copilot java-testcontainers

3Manually: put the files in place

.github/skills/java-testcontainers/SKILL.md

From the same set554

The whole set →
git-commit official github This skill reviews Git changes, stages related files, and creates Conventional Commits. Use it when you want an agent to make one commit or split work into separate commits. GitHub Copilot 47,165installs excalidraw-diagram-generator official github Turn a plain-language description into an Excalidraw diagram. Useful for mapping processes, system structure, and relationships between entities. GitHub Copilot 31,639installs multi-stage-dockerfile official github This skill guides GitHub Copilot in writing multi-stage Dockerfiles for different languages and frameworks. Use it when the final runtime image should contain fewer build dependencies. GitHub Copilot 29,688installs documentation-writer official github Skill that turns the agent into a technical writer following the Diátaxis framework: tutorials, how-to guides, reference, and explanation. Proposes structure before writing. GitHub Copilot 27,757installs prd official github Turns a feature idea into a structured PRD with user stories, technical requirements, and risks. Use it when planning a software feature or an AI-powered one. GitHub Copilot 24,035installs refactor official github This skill reshapes existing code without changing its external behavior. Use it for gradual cleanup of large functions, duplication, weak types, and code smells. GitHub Copilot 22,321installs java-springboot official github Gives GitHub Copilot Spring Boot development practices, from project layout to tests and security. Use it when writing or reviewing Java application code. GitHub Copilot 21,272installs create-readme official github This skill reviews a project and creates a structured README.md. Use it when the repository needs clear documentation based on its actual files and code. GitHub Copilot 19,081installs

Similar

analyze-data-quality official Data Analytics Maintainers Evaluates whether datasets and metric tables are reliable enough for dashboards or models. Helps catch duplicates and anomalies. CX Codex GP ChatGPT 9installs verification official Vercel Labs Traces and tests full user flows end-to-end across browser, API, and data layers when a dev server starts or something breaks. CX Codex GP ChatGPT 8installs spinning-up-deep-rl Alireza Rezvani A deep RL knowledge base for Claude Code, covering algorithms, policy gradients, and silent bugs. Use it when building or checking RL experiments. Claude Code 8installs web-perf official Cloudflare Audits web page performance using Chrome DevTools MCP. Measures Core Web Vitals and inspects render-blocking assets. CX Codex GP ChatGPT 5installs validate-data official Data Analytics Maintainers Audits analytical reports, SQL queries, metrics, and charts before sharing them with stakeholders or basing decisions on them. CX Codex GP ChatGPT 4installs circleci-cli official CircleCI Operates and troubleshoots CircleCI pipelines via the CircleCI CLI. Useful for validating configs, checking build failures, and triggering jobs directly from Codex. CX Codex GP ChatGPT 4installs improve-codebase-architecture Matt Pocock This skill scans a codebase for architectural friction, then builds a visual HTML report with refactoring candidates. Use it before a deeper architecture review. Claude Code 1,163,035installs design-taste-frontend Leonxlnx This skill directs the design of public pages and work screens, then checks the result in a browser through screenshots. Use it when an interface feels generic or unfinished. Claude Code CX Codex Cursor +1 673,100installs

Questions about java-testcontainers

How to install java-testcontainers for GitHub Copilot?

Install it using gh skill install github/awesome-copilot java-testcontainers or run npx skills add github/awesome-copilot --skill java-testcontainers.

What does the java-testcontainers skill do?

It instructs Copilot to generate Java integration tests adhering to Testcontainers 2.x standards, proper wait strategies, and JUnit Jupiter lifecycles.

Does Testcontainers 2.x support JUnit 4?

No, Testcontainers 2.x has dropped JUnit 4 support. The skill focuses exclusively on JUnit Jupiter.

Source text

SKILL.md · MIT
---
name: java-testcontainers
description: 'Write reliable integration tests in plain Java with Testcontainers 2.x: JUnit Jupiter lifecycle, singleton containers, reuse, generic containers, wait strategies, networks, init scripts, Docker Compose, CI and Docker/Podman setup. Use when adding or fixing Testcontainers tests, or migrating from 1.x. Framework-neutral.'
---

# 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

1. Detect the existing version (`pom.xml` / `build.gradle`) and test framework (JUnit Jupiter). Testcontainers 2.x has no JUnit 4 support.
2. Pick the smallest container that matches production (same DB engine and major version; never H2 as a stand-in for behavior you care about).
3. Choose a lifecycle (table below), configure waiting, wire connection details into the code under test.
4. 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 stays `org.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 under `org.testcontainers.containers`.
- Module container classes are no longer generic: `PostgreSQLContainer`, not `PostgreSQLContainer<?>`.
- 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); `DockerComposeContainer` is still present in 2.0.5 (older API); prefer `ComposeContainer`.

```xml
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers-bom</artifactId>
      <version>2.0.5</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers-junit-jupiter</artifactId>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers-postgresql</artifactId>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.7.14</version>
    <scope>test</scope>
  </dependency>
</dependencies>
```

Gradle: `testImplementation platform("org.testcontainers:testcontainers-bom:2.0.5")`, then the same Testcontainers artifacts without versions, plus `testRuntimeOnly "org.postgresql:postgresql:42.7.14"`. The Testcontainers module does not bundle the JDBC driver; skip the explicit driver when the project already depends on one (e.g. via Spring Boot's BOM).

## Minimal test

```java
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.postgresql.PostgreSQLContainer;

@Testcontainers
class CustomerStoreIT {

    @Container
    static final PostgreSQLContainer POSTGRES = new PostgreSQLContainer("postgres:17-alpine");

    @Test
    void connects() throws Exception {
        try (var c = java.sql.DriverManager.getConnection(
                POSTGRES.getJdbcUrl(), POSTGRES.getUsername(), POSTGRES.getPassword())) {
            org.junit.jupiter.api.Assertions.assertTrue(c.isValid(2));
        }
    }
}
```

Always pin the image tag (never `latest`); match the production major version.

## Lifecycle decision

| Need | Pattern |
| --- | --- |
| One container per test class | `static @Container` field |
| Fresh container per test method (slow, strong isolation) | non-static `@Container` field |
| One container for the whole test run (fastest) | singleton holder, see `references/lifecycle-and-reuse.md` |
| Keep containers between local runs | `withReuse(true)` + opt-in property, local only |

Prefer sharing a container and isolating **data** (truncate/rollback, unique schema or DB per test) over restarting containers.

## Checklist

- [ ] Image tag pinned and matches production.
- [ ] Wait strategy meaningful (module defaults are usually fine; custom for `GenericContainer`).
- [ ] No fixed host ports; use `getMappedPort`/`getHost`.
- [ ] Containers shared across classes where possible (singleton).
- [ ] Integration tests named `*IT` and run by failsafe (Maven) or a separate Gradle test task, so unit tests stay fast.
- [ ] No secrets or real credentials in test containers.
- [ ] CI runner has Docker; log output is captured on failure.

## References

- `references/lifecycle-and-reuse.md`: per-class/per-method, singleton pattern, reuse, parallel runs, data isolation.
- `references/containers-and-waiting.md`: modules vs `GenericContainer`, wait strategies, env/config, init scripts, copy files, networks, multi-container setups, Docker Compose.
- `references/environment-ci-troubleshooting.md`: Docker/Podman/Colima setup, CI, private registries, performance, common errors, 1.x to 2.x migration table.

Official docs: <https://java.testcontainers.org/>

Upgrading to 2.x: no dedicated migration page was found on java.testcontainers.org; read the 2.0.0 release notes <https://github.com/testcontainers/testcontainers-java/releases/tag/2.0.0> and all releases <https://github.com/testcontainers/testcontainers-java/releases> for the target version, and prefer them over this skill when they conflict.

© github · MIT · github/awesome-copilot

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor