Skip to content

Introduce SUITE, CLASS, and MANUAL lifecycle modes for @Testcontainer annotation, replacing the previous boolean value.#127

Draft
rhusar wants to merge 1 commit intoarquillian:mainfrom
rhusar:container-lifecycle-scoping
Draft

Introduce SUITE, CLASS, and MANUAL lifecycle modes for @Testcontainer annotation, replacing the previous boolean value.#127
rhusar wants to merge 1 commit intoarquillian:mainfrom
rhusar:container-lifecycle-scoping

Conversation

@rhusar
Copy link
Copy Markdown
Member

@rhusar rhusar commented Apr 30, 2026

  • SUITE-scoped containers are started once and shared across test classes,
  • CLASS-scoped containers follow the existing per-class behavior,
  • MANUAL-scoped containers are injected but never started/stopped by the framework.

Add TestcontainerLifecycle enum for container lifecycle scoping

Suite-scoped containers use @SuiteScoped registry created in BeforeSuite, while class-scoped containers use a fresh @ClassScoped registry per test class. TestcontainerRegistryView routes lookups to the correct registry based on lifecycle value.

Resolves: #126

@rhusar
Copy link
Copy Markdown
Member Author

rhusar commented Apr 30, 2026

This is a feature we would need in WildFly clustering test suite when running a group of tests against an Infinispan server and there are also Elytron TS use cases.

Opening as draft before I head over for PTO later today so I don't forget all about it while I am off. Nevertheless, seems fully functional but haven't tested it outside of the integration testsuite done here. Note the complications of the TestcontainerRegistryView class, which is working around the injection of the same class but in different scoped; all explained in the Javadoc.

This will need adaptation as the #123 and #124 get merged.

Have a look @jamezp @jasondlee and might be of interest to @haster too

…annotation, replacing the previous boolean value.

SUITE-scoped containers are started once and shared across test classes,
CLASS-scoped containers follow the existing per-class behavior,
MANUAL-scoped containers are injected but never started/stopped by the framework.

Add TestcontainerLifecycle enum for container lifecycle scoping

Suite-scoped containers use @SuiteScoped registry created in BeforeSuite, while class-scoped containers use a fresh @ClassScoped registry per test class.
TestcontainerRegistryView routes lookups to the correct registry based on lifecycle value.

Resolves: arquillian#126

Signed-off-by: Radoslav Husar <rhusar@redhat.com>
Signed-off-by: Radoslav Husar <radosoft@gmail.com>
@haster
Copy link
Copy Markdown
Contributor

haster commented Apr 30, 2026

This is gonna be really useful to us. We re-use our containers between different testclasses, mostly for performance reasons. This PR is shaping up to be exactly what we planned to send in.

Claude is also very happy:

Strong design choices:

  • MANUAL cleanly replaces the asymmetric value=false (started=false, stopped=true). Now all three
    states are explicit.
  • SUITE containers start on first encounter via the if (!description.instance.isRunning()) guard,
    persist across test classes, stop at AfterSuite. Exactly the cube STARTANDSTOP semantics.
  • TestcontainerRegistryView solves a real Arquillian SPI limitation (you can't qualify Instance by
    scope in a TestEnricher) — clean approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running container with longer life span

2 participants