Skip to content

TOMEE-4714 - Allow to restart the TomEE embedded runner and add a container lifecycle mode to the JUnit 5 extension (10.x) - #2957

Merged
rzo1 merged 1 commit into
tomee-10.xfrom
TOMEE-4714-10.x
Sep 28, 2026
Merged

rzo1 merged 1 commit into
tomee-10.xfrom
TOMEE-4714-10.x

Conversation

@rzo1

@rzo1 rzo1 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/TOMEE-4714

Problem

@RunWithTomEEEmbedded only works for the first container start of a JVM. The extension closes the container after each test (class), but TomEEEmbeddedApplicationRunner#close() never resets started, so the next start(...) returns early. No container is started and @Application / @RandomPort fields stay null.

Change

  • TomEEEmbeddedApplicationRunner#close() resets started, so the runner can be started again.
  • @RunWithTomEEEmbedded gets a mode (PER_JVM, PER_ALL, PER_EACH, AUTO), like @RunWithApplicationComposer. AUTO is the default and keeps the current behaviour: it follows the lifecycle of the test instance.
  • @RunWithTomEEEmbedded is @Inherited now, like @RunWithApplicationComposer.
  • TomEEEmbeddedBase gets a start(Class) overload, as there is no test instance yet if the container is started for a test class.
  • PER_JVM can't be combined with the other modes in the same JVM, same restriction as for the ApplicationComposer.

Tests

Two new surefire executions in tomee-embedded, each running its test classes in one shared JVM:

  • junit5-extension-modes: PER_EACH, PER_ALL and AUTO (both test instance lifecycles). The container is started 8 times in that JVM.
  • junit5-extension-mode-per-jvm: two test classes sharing a single container.

Not covered by a test: the guard rejecting a mix of PER_JVM and the other modes.

…tainer lifecycle mode to the JUnit 5 extension

TomEEEmbeddedApplicationRunner#close() did not reset the started flag, so the runner could not be started again. The JUnit 5 extension closes the container after each test (class), so only the first container start of a JVM worked.

@RunWithTomEEEmbedded now has a mode (PER_JVM, PER_ALL, PER_EACH, AUTO) similar to @RunWithApplicationComposer and is @inherited like it. AUTO keeps the current behaviour and follows the lifecycle of the test instance.

TomEEEmbeddedBase got a start(Class) overload, as there is no test instance yet if the container is started for a test class.
@rzo1
rzo1 merged commit 16b3ca9 into tomee-10.x Sep 28, 2026
1 check passed
@rzo1
rzo1 deleted the TOMEE-4714-10.x branch September 28, 2026 18:35
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.

2 participants