Fix parameterized setup to run once after initialization by hugoncosta · Pull Request #1190 · openrewrite/rewrite-testing-frameworks · GitHub
Skip to content

Fix parameterized setup to run once after initialization - #1190

Open
hugoncosta wants to merge 2 commits into
openrewrite:mainfrom
hugoncosta:fix/junit-parameterized-setup-once
Open

hugoncosta wants to merge 2 commits into
openrewrite:mainfrom
hugoncosta:fix/junit-parameterized-setup-once

Conversation

@hugoncosta

@hugoncosta hugoncosta commented Oct 14, 2026 •

Copy link
Copy Markdown

What's changed?

Fix ParameterizedRunnerToParameterized so declared setup methods run exactly once, after constructor or field parameters are assigned.

  • Recognize both JUnit 4 @Before and Jupiter @BeforeEach.
  • Remove the lifecycle annotation when moving setup invocation into the generated initialization method.
  • Invoke each declared setup method after initialization.
  • Add setupRunsOnceAfterParameterAssignment, which checks the assigned value and setup count, and correct the existing expected output.

What's your motivation?

Extract the Java setup correction from #1189 into a focused review, following the request to split the Kotlin migration contribution into smaller PRs.

Keeping a Jupiter lifecycle annotation while also calling setup from parameter initialization can invoke setup twice and run it before injected fields are assigned.

Verification

  • All nine ParameterizedRunnerToParameterizedTest cases pass on this branch.
  • Two changed files; one commit directly above upstream main.
  • git diff --check passes.
  • This branch is independent of the remaining Kotlin contribution.

Local verification used public build plugin 2.23.0 / Rewrite 8.90.4 through an uncommitted build override. The repository's default build still requires CI verification.

Related: #1188, #1189. This is the first of the planned smaller contributions; it does not close the Kotlin parity issue.

Companion split: #1191. Both PRs are independently based on upstream main.

Remove declared Before and BeforeEach lifecycle annotations when setup moves
into parameter initialization. Invoke each setup method once after constructor
or field parameters are assigned, and cover the double invocation regression.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant