TOMEE-4714 - Allow to restart the TomEE embedded runner and add a container lifecycle mode to the JUnit 5 extension - #2956
Merged
Merged
Conversation
…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.
jungm
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/TOMEE-4714
Problem
@RunWithTomEEEmbeddedonly works for the first container start of a JVM. The extension closes the container after each test (class), butTomEEEmbeddedApplicationRunner#close()never resetsstarted, so the nextstart(...)returns early. No container is started and@Application/@RandomPortfields staynull.Change
TomEEEmbeddedApplicationRunner#close()resetsstarted, so the runner can be started again.@RunWithTomEEEmbeddedgets amode(PER_JVM,PER_ALL,PER_EACH,AUTO), like@RunWithApplicationComposer.AUTOis the default and keeps the current behaviour: it follows the lifecycle of the test instance.@RunWithTomEEEmbeddedis@Inheritednow, like@RunWithApplicationComposer.TomEEEmbeddedBasegets astart(Class)overload, as there is no test instance yet if the container is started for a test class.PER_JVMcan'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_ALLandAUTO(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_JVMand the other modes.