Skip to content

Start @StartStop MockWebServer for @Nested JUnit 5 tests - #9634

Open
HDPark95 wants to merge 1 commit into
lysine-dev:mainfrom
HDPark95:fix/issue-9546-startstop-nested
Open

Start @StartStop MockWebServer for @Nested JUnit 5 tests#9634
HDPark95 wants to merge 1 commit into
lysine-dev:mainfrom
HDPark95:fix/issue-9546-startstop-nested

Conversation

@HDPark95

@HDPark95 HDPark95 commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #9546.

A @StartStop MockWebServer field declared on an outer class is never started when the test runs inside a @Nested inner class, so a nested test that uses the server fails with IllegalStateException: call start() first.

StartStopExtension.beforeEach resolved instance fields from context.testInstance (the innermost @Nested instance) and context.requiredTestClass (the nested class). A @StartStop field on an enclosing class is on neither, so it was never found or started. Top-level tests were unaffected because the test instance and its declaring class line up.

The fix walks context.requiredTestInstances.allInstances, which returns every instance in the enclosing hierarchy, and starts the annotated fields on each. Behavior is unchanged for non-nested tests, where allInstances is the single test instance.

Added NestedStartStopTest, which declares a @StartStop server on the outer class and one on a @Nested inner class and asserts both are started from a nested test. It fails before the change and passes after.

StartStopExtension.beforeEach resolved instance fields from
context.testInstance (the innermost @nested instance) and
context.requiredTestClass (the nested class), so a @startstop
MockWebServer field declared on an enclosing class was never started.
A nested test that touched the server failed with "call start() first".

Walk context.requiredTestInstances.allInstances instead and start the
annotated fields on every instance in the hierarchy. Behavior is
unchanged for non-nested tests, where allInstances is the single
test instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

MockWebServer @StartStop field on outer class not started for @Nested JUnit 5 tests

1 participant