Quick revision
The short answer
The lessons are to prefer tools with broad ecosystem support and stable extension points, as the JUnit Platform showed by separating the runner from the programming model; to avoid coupling our code to framework internals and base classes, since composition and extensions survive upgrades better; to budget for migration as normal maintenance with automated refactoring; to watch health signals such as release cadence, maintainers and build and IDE integration; and to keep tests readable and as framework-neutral as practical, so the next move is cheaper.
What to remember
In this answer, we used the history of Java test frameworks, from JUnit 3 through TestNG and JUnit 4 to the JUnit Platform with JUnit 5 and 6, to draw lessons for choosing long-lived tools. We prefer broad ecosystems and stable extension points, couple to contracts rather than internals, budget for migration as normal maintenance with automated refactoring, watch health signals such as release cadence and maintainers, and keep tests plain enough that the next move is cheap.
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.
The lessons are to prefer tools with broad ecosystem support and stable extension points, as the JUnit Platform showed by separating the runner from the programming model; to avoid coupling our code to framework internals and base classes, since composition and extensions survive upgrades better; to budget for migration as normal maintenance with automated refactoring; to watch health signals such as release cadence, maintainers and build and IDE integration; and to keep tests readable and as framework-neutral as practical, so the next move is cheaper.
Why this question is asked
A Java codebase that lives for fifteen years will outlast several generations of its tools. Test frameworks are a good case study, because they have been replaced several times and every large organisation carries the cost of those changes. Interviewers ask senior candidates this question to hear how they choose tools for the long term and how they limit the damage when a choice ages. In this answer, we will walk through the history briefly, then draw out the lessons one at a time with examples: the value of a platform, coupling, migration as maintenance, health signals and framework-neutral tests.
1A Short History of Java Test Frameworks
JUnit 3 tests extended a TestCase base class and were found by naming convention: methods starting with test. TestNG arrived in 2004 with annotations, groups, data providers and configurable lifecycles, and many teams moved to it for those features. JUnit 4 adopted annotations in 2006 and stayed dominant for a decade, with runners and rules as extension points. JUnit 5 in 2017 split into the JUnit Platform, which launches tests, and Jupiter, the programming model with a new extension API. JUnit 6, released in 2025, continued on the same platform with a Java 17 baseline and one version number for all modules.
Each move had a cost. JUnit 3 to 4 meant removing base classes. JUnit 4 to 5 meant replacing runners and rules with extensions, and @RunWith(SpringRunner.class) with @ExtendWith or nothing at all, since Spring Boot's test annotations already include it. The suites that suffered most were not the biggest ones; they were the ones most tied to the old framework's internals.
| Framework | How tests were written | What made migration hard |
|---|---|---|
| JUnit 3 | extends TestCase, testX() names | Base classes everywhere |
| TestNG | Annotations, groups, data providers | Deep @Before hierarchies, testng.xml logic |
| JUnit 4 | Annotations, runners, rules | Custom runners, one runner per class |
| JUnit 5 | Platform plus Jupiter extensions | Replacing runners and rules |
| JUnit 6 | Same platform and Jupiter model | Mostly baseline and deprecations |
2Lesson 1: Prefer Platforms With Stable Extension Points
The most important design change in this history was the JUnit Platform. Before it, IDEs and build tools had to understand each framework separately, and a framework change meant a tooling change. The platform defines one launcher API that tools talk to, and test engines plug into it: Jupiter, the Vintage engine for JUnit 3 and 4 tests, a TestNG engine, jqwik, Cucumber and others. A team can run old and new tests side by side in one build and one report, which turns a big-bang migration into a gradual one.
The general lesson for any long-lived tool is to prefer ones that separate the stable contract from the part that evolves. A tool with a documented extension API, used by a broad ecosystem, tends to keep that API stable because many others depend on it. A tool whose extension story is to subclass its internal classes will break us at the next major version.
3Lesson 2: Couple to Contracts, Not Internals
The suites that migrated badly had built on framework internals: custom JUnit 4 runners that reimplemented test discovery, TestNG base classes six levels deep, utilities that read framework state through reflection. Each of those had to be rewritten, not just translated.
Composition survives better. A test that uses a small helper object for test data, an extension for a database, and plain assertions depends on very little of the framework. When JUnit 4 rules became Jupiter extensions, teams with a handful of focused rules converted them in days; teams with a custom runner that did everything spent months. The same principle applies to build tools, web frameworks and logging: wrap the parts we use behind our own small interfaces where it is cheap, and avoid inheriting from framework classes when an annotation or a delegate will do.
4Lesson 3: Budget for Migration as Normal Maintenance
Every long-lived tool will eventually need to be replaced or upgraded across a major version. Organisations that treat this as an exceptional project tend to postpone it until the old tool is unsupported, and then do it in a hurry. Organisations that treat it as maintenance, a small, steady share of capacity, perhaps 5 to 10 percent per team for platform upkeep, migrate gradually and with less risk.
Automated refactoring changes the economics. Tools such as OpenRewrite have recipes that convert JUnit 4 tests to Jupiter, update assertions and swap annotations across thousands of files in one reviewed change, leaving people to handle only the unusual cases. When choosing a tool today, I would count whether such automated migration paths exist as part of its long-term cost.
- Ecosystem breadthbuild tools, IDEs, CI, other libraries support it
- Stable extension pointsdocumented APIs, not internal classes
- Project healthrelease cadence, several active maintainers
- Migration pathsside-by-side running, automated refactoring
- Can we limit our coupling to it?YesAdopt, with a small wrapper where cheapNoPrefer a more modular option
5 steps in order. Play them, or step through them one at a time.
Long-term cost depends as much on how we use a tool as on which tool we pick.
5Lesson 4: Watch Health Signals, and Lesson 5: Keep Tests Neutral
Tools rarely die suddenly; they show signs first. Releases become rare, issues pile up without answers, the project depends on one maintainer, new Java versions are supported months late, or build tools and IDEs stop updating their integration. I would review these signals for the main tools in our stack once a year, in the same way we review dependencies for security, so we start a migration while we still have time to do it calmly.
Finally, the cheapest future migration is the one our tests make easy. Tests that read as plain arrange, act, assert, with assertions from a library such as AssertJ, test data from builders and setup in small helpers, depend on the framework only for a few annotations. Moving them is close to a search and replace. Tests that encode behaviour in framework features, such as complex testng.xml group logic or dependencies between test methods, carry that logic with them and have to be redesigned. Keeping tests boring is a long-term investment.
6Follow-up questions
Would you still choose TestNG for a new project today?
For most new Java projects I would choose JUnit Jupiter, because of its ecosystem support, Spring integration and extension model, and because it runs on the platform that other engines share. TestNG remains a reasonable choice where a team relies on its strengths, such as some data-driven UI suites, and it can run on the JUnit Platform through its engine, which keeps options open.
How do you decide when a migration is worth doing?
Weigh the ongoing cost of staying, such as missing features, poor support for new Java versions and duplicate tooling, against the migration cost, which automated refactoring can reduce sharply. When the old tool blocks upgrades of other parts of the stack, the decision is usually made for us, so it is better to start earlier.
Is wrapping every framework behind our own interfaces a good idea?
Not every framework and not always. Wrapping adds code and can hide useful features. I would wrap only where the coupling is broad and the wrapper is thin, for example a test data helper or an HTTP client facade, and otherwise rely on choosing tools with stable public APIs.
7Conclusion
In this answer, we used the history of Java test frameworks, from JUnit 3 through TestNG and JUnit 4 to the JUnit Platform with JUnit 5 and 6, to draw lessons for choosing long-lived tools. We prefer broad ecosystems and stable extension points, couple to contracts rather than internals, budget for migration as normal maintenance with automated refactoring, watch health signals such as release cadence and maintainers, and keep tests plain enough that the next move is cheap.
Open with
Looking at that history, the pain of each move came less from the new framework and more from how tightly tests were tied to the old one. Suites built on base classes, custom runners or deep TestNG setup hierarchies had to be rewritten, while plain tests with helpers and a few annotations moved almost mechanically.
Then, if they want more
So my first lesson is to prefer tools with broad ecosystem support and stable extension points. The JUnit Platform is the best example: it separated the launcher that IDEs and build tools talk to from the programming model, so Jupiter, the Vintage engine and even TestNG can run side by side in one build, which makes migration gradual.
Second, couple to public contracts, not internals; composition and extensions survive upgrades, inheritance from framework classes does not. Third, budget for migration as normal maintenance, a small steady share of capacity, and use automated refactoring like OpenRewrite recipes, which can convert thousands of tests in one reviewed change.
Fourth, watch health signals once a year: release cadence, number of maintainers, support for new Java versions, and build tool and IDE integration, so we move before we are forced. And fifth, keep tests readable and as framework-neutral as practical, with AssertJ assertions and plain helpers, so the next migration, whatever it is, stays cheap.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- JUnit 4, JUnit 3, JUnit 5, 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, Mockito documentation
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 "Test frameworks in Java have changed several times (JUnit 3, TestNG, JUnit 4, JUnit 5...": https://scrivio-interview-library.netlify.app/java/testng/68b93cf14f/