Add MigrateHudsonTestCaseToJenkinsRule recipe#1718
Add MigrateHudsonTestCaseToJenkinsRule recipe#1718Fikri-20 wants to merge 3 commits intojenkins-infra:mainfrom
MigrateHudsonTestCaseToJenkinsRule recipe#1718Conversation
Implements an OpenRewrite ScanningRecipe that migrates JUnit 3-style test classes extending HudsonTestCase to the modern JUnit 4 @rule JenkinsRule pattern. Removes the extends clause, inserts the @rule field, converts setUp/tearDown lifecycle methods, annotates JUnit 3 test methods with @test, and prefixes delegated HudsonTestCase method calls with j.
Covers the five core scenarios: extends removal with @rule field insertion, setUp/tearDown lifecycle conversion, prefixing delegated method calls with j., no-op behavior on already-modern classes, and setUp methods without a super call.
Exposes the new recipe under the io.jenkins.tools.pluginmodernizer.MigrateHudsonTestCaseToJenkinsRule declarative name and chains it as the first step of MigrateToJUnit5 so that HudsonTestCase classes are modernized to JenkinsRule before the JUnit 5 transformations run.
|
Mhh what is the reason to migrate to JUnit 4 when there is on on-going migration to ban and migrate to JUnit Jupiter 5 (and more). Can you explain further? |
|
You're right that The issue is that This recipe handles that first hop: Let me know if that makes sense, or if you'd prefer a different approach, happy to adjust! |
Adds a new OpenRewrite recipe
MigrateHudsonTestCaseToJenkinsRulethat migratesJUnit 3-styleJenkins test classes extendingHudsonTestCaseto the modernJUnit 4 @Rule JenkinsRulepattern.The recipe performs the following transformations on any class extending
HudsonTestCase:HudsonTestCaseclause@Rule public JenkinsRule j = new JenkinsRule();as the first fieldsetUp()to@Beforeand stripssuper.setUp()tearDown()to@Afterand stripssuper.tearDown()JUnit 3-style public void test*()methods with@TestHudsonTestCasemethod calls with j.The recipe is registered standalone and chained as the first step of
MigrateToJUnit5soHudsonTestCaseclasses are modernized before theJUnit 5transformations run.Testing done
Verified against
jenkinsci/backlog-plugin, which still extendsHudsonTestCase.Install the recipe locally:
Clone the target plugin and run the recipe:
Recipe execution output (relevant lines):
Resulting diff:
The recipe correctly removed extends
HudsonTestCase, swapped theHudsonTestCaseimport forJenkinsRule, added theorg.junit.Ruleimport, and inserted the@Rule public JenkinsRule j = new JenkinsRule();field as the first member.Submitter checklist