Quick revision
The short answer
I would migrate gradually: first put the JUnit Platform under the whole build and keep running JUnit 4 tests on the Vintage engine, then convert module by module with automated OpenRewrite recipes for annotations and assertions, and convert runners and rules to extensions by hand. CI stays green at every step. I would justify the work with concrete gains: Vintage is deprecated in JUnit 6, modern tools and frameworks target Jupiter, and Jupiter brings parallel execution and better extension support.
What to remember
In this answer, we justified the migration with JUnit 6's deprecation of Vintage, ecosystem support that targets Jupiter, and measurable gains such as parallel execution. We started safely by running everything on the JUnit Platform with Vintage, automated the mechanical changes with OpenRewrite one module at a time, converted runners and rules to extensions by hand, and rolled out with matching test counts, green CI and import checks that prevent sliding back, before finally removing Vintage.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would migrate gradually: first put the JUnit Platform under the whole build and keep running JUnit 4 tests on the Vintage engine, then convert module by module with automated OpenRewrite recipes for annotations and assertions, and convert runners and rules to extensions by hand. CI stays green at every step. I would justify the work with concrete gains: Vintage is deprecated in JUnit 6, modern tools and frameworks target Jupiter, and Jupiter brings parallel execution and better extension support.
Why this question is asked
Tens of thousands of tests represent years of knowledge about how the system should behave, and nobody wants to risk them for a cosmetic change. So a migration like this needs both a safe plan and a reason that convinces people who care about delivery. Interviewers ask it to see whether we can lead a large, boring, risky change without stopping feature work. In this answer, we will build the business case, set up a safe starting point with Vintage, automate the bulk of the work, handle runners and rules by hand, and organise the rollout so the build never breaks.
1Building the Case for Migrating
Before planning, we need to explain why this deserves engineering time. The strongest argument today is that JUnit 6 deprecated the Vintage engine, the bridge that lets JUnit 4 tests run on the modern platform. JUnit 4 itself is in maintenance mode with only occasional fixes. So staying on JUnit 4 means our tests slowly drift away from what the ecosystem supports.
The second argument is tool and framework support. Spring Boot's test support, Testcontainers, Mockito's extension and most new testing libraries target Jupiter first, and some features only exist there. The third is concrete capability: Jupiter's parallel execution can cut CI time, parameterized and nested tests make suites easier to read, and composable extensions replace the one-runner-per-class limit. If CI takes 40 minutes and parallel execution could make it 25, that is time every developer gets back on every pull request, and it can be measured in a pilot module first.
2A Safe Starting Point: Platform Plus Vintage
The first step changes no test at all. We switch every module's build to run on the JUnit Platform, add the Jupiter engine for new tests and the Vintage engine for old ones. Now new tests can be written in Jupiter immediately, and the old tests keep running unchanged.
We compare test counts before and after this switch. If the old build ran 41,230 tests, the new one must report 41,230 too. A missing number usually means a surefire or Gradle configuration that does not pick up the Platform, and catching it now prevents us from silently losing tests later.
3Automating the Bulk With OpenRewrite
Most of the change is mechanical: imports, annotation names, assertion argument order, expected exceptions and timeouts. OpenRewrite is a tool that parses Java code into a full syntax tree with types and applies recipes, which are automated, type-aware refactorings. It has a JUnit 4 to 5 migration recipe that handles these mechanical parts, and it can run as a Maven or Gradle plugin on one module at a time.
Notice that we review the diff like any other change. Automated tools are very good but not perfect, and the assertion message order is a classic place where a hand-written helper can confuse them. Running module by module keeps each pull request reviewable.
4Converting Runners and Rules by Hand
The part that needs people is custom runners and rules, because each one is a small piece of behaviour that must be redesigned as an extension. Well-known ones have direct replacements: SpringRunner becomes SpringExtension, which @SpringBootTest already includes, MockitoJUnitRunner becomes MockitoExtension, TemporaryFolder becomes @TempDir, and ExpectedException becomes assertThrows. Custom rules, such as one that resets a fake clock or seeds a database, become small extensions implementing BeforeEachCallback and AfterEachCallback.
We start by listing every runner and rule in the code base with a count of uses. Usually a handful of custom ones cover most of the usage, so converting those first, and publishing the extensions in the shared test library, unblocks most modules.
5Rolling It Out Module by Module
The rollout is a loop, and CI stays green at every turn. We pick a module, run the recipe, convert its runners and rules, review, check that the test count is unchanged and that the tests still fail when they should, and merge. Then we add a build check that forbids new org.junit imports in that module, so it cannot slide back. Once all modules are done, we remove the Vintage engine and the JUnit 4 dependency.
I would start with one small module to tune the recipe and measure the effort per test, then do the modules with the most custom rules, then hand the rest to teams with a guide, a time budget and help from a small migration group. Spreading the work over a few months alongside feature work is safer than a big-bang weekend.
- Record the test countfor example 3,412 tests
- Run the OpenRewrite recipe
- Convert runners and rulesuse shared extensions
- Same test count and all green?YesMerge and forbid org.junit importsNoFix before merging
- Next module
- All modules done?YesRemove Vintage and JUnit 4NoContinue the loop
6 steps in order. Play them, or step through them one at a time.
6Follow-up questions
How do you make sure no tests are lost in the migration?
I compare the number of tests discovered and executed per module before and after, from the build reports, and require them to match. I also run mutation testing or deliberately break a few classes in a pilot module to confirm that migrated tests still fail when they should, because a test that silently stopped asserting is worse than a missing one.
Should we keep Vintage forever since it works?
No. It is a good bridge, but it is deprecated in JUnit 6, which means it may be removed in a future major version, and JUnit 4 itself is barely maintained. Keeping it forever also keeps two styles of tests in the code base and blocks features like Jupiter parallel execution for the old tests.
How do you estimate the effort?
I run the recipe on a pilot module and measure the hours spent per hundred tests on review and manual fixes, then multiply across modules, adding time for each custom runner and rule. With tens of thousands of tests, the automated part is usually quick; the estimate is driven by custom rules and unusual test setups.
7Conclusion
In this answer, we justified the migration with JUnit 6's deprecation of Vintage, ecosystem support that targets Jupiter, and measurable gains such as parallel execution. We started safely by running everything on the JUnit Platform with Vintage, automated the mechanical changes with OpenRewrite one module at a time, converted runners and rules to extensions by hand, and rolled out with matching test counts, green CI and import checks that prevent sliding back, before finally removing Vintage.
Open with
I would treat it as a gradual migration that never breaks the build. First, the justification: JUnit 6 deprecates the Vintage engine, JUnit 4 is barely maintained, and Spring Boot, Testcontainers and most new tools target Jupiter.
Then, if they want more
Jupiter also gives us parallel execution, which I would measure in a pilot module to put a number on CI minutes saved.
The first technical step changes no tests: every module runs on the JUnit Platform with both the Jupiter and Vintage engines, so new tests are written in Jupiter right away, and I check the test counts match before and after.
Then I would migrate module by module with OpenRewrite's JUnit 4 to 5 recipe, which handles imports, annotations, assertions and expected exceptions, and review each diff. Runners and rules need people, so I would count them, convert the common ones to extensions in a shared test library first, and map the standard ones to SpringExtension, MockitoExtension and @TempDir.
Each module merges only when the test count matches and CI is green, and then a build check forbids new JUnit 4 imports there. When the last module is done, we remove Vintage and JUnit 4 entirely.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- JUnit 4, JUnit 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your codebase has tens of thousands of JUnit 4 tests. How would you plan and justify...": https://scrivio-interview-library.netlify.app/java/junit/8d216af6a6/