testcontainers / testcontainers/testcontainers-java

[Feature]: JUnit Jupiter extension for reuse of containers

Open
#6,401 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type/feature
Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

Module

Core

Problem

Assume you have several integration tests splitted in some classes. All this tests can reuse the same container instance. If the container needs some time to setup that would be a great benefit.

Solution

By using the JUnit extension API it would be easy to create a custom annotation like this:

@ContainerConfig(name="containerA", needNewInstance=false) public void testFoo() {}

A container that is needed could be simply defined by a provider:

@ContainerProvider(name="containerA") public GenericContainer<?> createContainerA() {}

By using test lifecycle callbacks (https://junit.org/junit5/docs/current/user-guide/#extensions-lifecycle-callbacks) this could be achieved as a JUnit extension.

I would be happy to help by creating the feature :)

Benefit

Containers that are needed for multiple tests in multiple classes only need to be defined once and the instances can be reused.

Alternatives
Would you like to help contributing this feature?

Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the Core module and read the JUnit Jupiter extension API lifecycle callbacks referenced in the issue. Define how the proposed ContainerConfig and ContainerProvider annotations should register and reuse containers across test classes, then verify that shared instances are created once while needNewInstance requests remain isolated.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.