testcontainers / testcontainers/testcontainers-java
[Feature]: JUnit Jupiter extension for reuse of containers
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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