Quick revision
The short answer
I would choose widely used, actively maintained libraries with a record of supporting new JDKs quickly, and be wary of any library that depends on deep JVM hacks such as bytecode agents or private APIs unless it has very strong maintenance. Tests should depend on library details as little as possible, through fakes, simple stubs and limited use of advanced mocking. The platform team tracks dependency health and plans migrations early, and the approved list and its reasons are written into the testing standard and reviewed every year.
What to remember
In this answer, we saw that past test libraries faded either because their style made tests brittle or because they depended on JVM internals that new JDKs broke. From that we derived criteria: wide adoption, active maintenance with fast JDK support, public APIs over deep hacks, and low exit cost. We keep tests loosely coupled through fakes and basic stubbing, track library health and test on new JDKs early, and write the approved list with its reasons into the testing standard, reviewed yearly.
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 choose widely used, actively maintained libraries with a record of supporting new JDKs quickly, and be wary of any library that depends on deep JVM hacks such as bytecode agents or private APIs unless it has very strong maintenance. Tests should depend on library details as little as possible, through fakes, simple stubs and limited use of advanced mocking. The platform team tracks dependency health and plans migrations early, and the approved list and its reasons are written into the testing standard and reviewed every year.
Background to this question
The pattern in the question repeats roughly every decade: a library becomes popular, thousands of tests are written with it, then it stops keeping up with the JDK, and a migration project appears that nobody budgeted for. A senior leader is expected to learn from that pattern and build a system that makes the next one smaller. In this answer, we will look at why those libraries died, derive selection criteria from it, see how to write tests that are cheap to move, set up dependency health tracking, and write the governance into the standard.
1Why These Libraries Became Legacy
Each of the libraries in the question had a reason to exist and a reason to fade. JMock and EasyMock were early, and their strict record-and-expect styles produced brittle tests, so teams moved to Mockito's lighter style. PowerMock and JMockit could mock static methods, constructors and final classes, which nothing else could, but they did it by manipulating bytecode through custom class loaders or Java agents and by relying on JVM internals.
That second group is the important lesson. As the JDK started releasing every six months, strengthening encapsulation with modules, and restricting dynamically loaded agents, libraries that depended on internals broke with almost every release. Keeping up required steady, skilled maintenance, and when the maintainers moved on, the libraries stopped working on new JDKs. Thousands of tests were then stuck on a dead library, and the JDK upgrade was stuck with them.
| Library | Strength | Why it faded |
|---|---|---|
JMock, EasyMock | early, expressive mocks | strict styles, brittle tests |
PowerMock | mocks statics, finals, constructors | class loader tricks; stalled on new JDKs |
| JMockit | agent mocks almost anything | JVM internals; little maintenance |
| Mockito | simple API, lenient by default | still active; inline maker uses an agent too |
2Criteria for Choosing a Library
From that history we can write selection criteria that are concrete enough to apply. First, adoption: a library used by a large share of the ecosystem, and ideally bundled with our framework, as Mockito, JUnit and AssertJ are in Spring Boot's test starter, has many users who need it to keep working. Second, maintenance: several active maintainers, regular releases, and a record of supporting each new JDK within weeks of its release. We can check that history directly in release notes.
Third, how it works: a library that uses only public APIs is much safer than one that rewrites bytecode or uses JDK internals. That does not forbid such libraries, and Mockito's inline mock maker itself uses an agent, but it raises the bar on maintenance and tells us to limit how much of our suite depends on that feature. Fourth, exit cost: how hard would it be to move away? A library with a small, conventional API is easier to replace, manually or with automated recipes, than one with its own complex DSL.
3Writing Tests That Are Cheap to Move
The best protection is not choosing the perfect library, which nobody can do ten years ahead, but limiting how deeply tests depend on any library. Tests that use fakes, simple hand-written implementations of our own interfaces, depend on no mocking library at all. Tests that use only basic stubbing and verification are easy to convert, often automatically. Tests that use static mocking, constructor mocking, deep stubs or partial mocks are the ones that tie us to one library's internals.
- Fakes and real objectsno library coupling
- Basic stubs and verifyeasy to convert, often automatically
- Spies, deep stubs, captors on genericsmoderate coupling
- Static, constructor and final mockingtied to library internals and JDK changes
4 layers, from the top down. Step through them one at a time.
So the standard encourages the first two styles and treats advanced features as exceptions that need a reason. Code designed with injected dependencies, such as an injected Clock, makes this easy, because there is nothing static to mock.
4Tracking Dependency Health
Somebody must watch. The platform team keeps a simple health record for every approved test library: last release date, number of active maintainers, supported JDK versions, open issues about the newest JDK, and how many of our tests use it and which advanced features they use. Most of this can be collected automatically from build files and release feeds.
Every new JDK release, and certainly every LTS, the platform team builds a representative part of the estate on it, ideally on early-access builds, and records which test libraries fail. A library that falls behind for two releases goes on a watch list; one that stops releasing goes on a migration plan, with an estimate based on our own usage counts. Because we start when the warning signs appear, the migration happens on our schedule instead of during a blocked upgrade.
- Record health for each approved libraryreleases, maintainers, JDK support, our usage
- Build on the next JDK earlyfind failures before upgrade day
- Library falling behind?YesWatch list, then migration planNoKeep approved
- Review the approved list yearlyreasons written in the standard
4 steps in order. Play them, or step through them one at a time.
5Writing It Into the Standard
Finally, the decision must be written down, with its reasons, because people change roles and reasons are what let the next leader decide well. The testing standard has a short section with the approved libraries for each purpose: JUnit for running tests, AssertJ for assertions, Mockito for mocks, Testcontainers for infrastructure, WireMock for HTTP, and so on. For each one it records why it was chosen and which features to avoid, such as 'mockStatic only with a reason'.
Adding a new library goes through a lightweight request: what problem it solves that the approved ones do not, and how it scores on the criteria. The list is reviewed once a year, using the health record. This keeps the company on a small set of healthy tools, makes any future migration smaller because usage is limited and known, and turns the next 'dead library' from a crisis into a planned piece of work.
6Follow-up questions
Isn't Mockito also at risk, since its inline mock maker uses an agent?
Partly, which is why the guidance limits static and final mocking and asks for the agent to be configured with -javaagent at JVM start. Mockito's broad adoption and active maintenance make it the safest choice today, but the standard still treats its advanced features as exceptions.
Should teams be allowed to pick their own libraries?
Within the approved list, yes, for example Spock in a Groovy module or MockK in Kotlin. Outside the list, through the lightweight request, so the platform team knows what to track.
How much effort does this governance take?
Very little once automated: a dashboard of library usage and release health, an early JDK build, and a yearly review meeting. That is far cheaper than one unplanned migration of thousands of tests.
7Conclusion
In this answer, we saw that past test libraries faded either because their style made tests brittle or because they depended on JVM internals that new JDKs broke. From that we derived criteria: wide adoption, active maintenance with fast JDK support, public APIs over deep hacks, and low exit cost. We keep tests loosely coupled through fakes and basic stubbing, track library health and test on new JDKs early, and write the approved list with its reasons into the testing standard, reviewed yearly.
Open with
I would start from why those libraries died. JMock and EasyMock lost to Mockito's lighter style, but PowerMock and JMockit died because they relied on bytecode agents, custom class loaders and JVM internals, and once the JDK started releasing every six months and restricting internals, they needed constant maintenance that stopped.
Then, if they want more
So my criteria are: wide adoption, ideally bundled with our framework like Mockito and JUnit in Spring Boot's test starter; active maintenance with a record of supporting new JDKs within weeks; public APIs rather than deep JVM hacks unless maintenance is very strong; and a low exit cost.
Second, I would make tests cheap to move, by preferring fakes and real objects, using basic stubbing and verification, and treating static, constructor and final mocking as exceptions with a reason.
Third, the platform team tracks health for every approved library, releases, maintainers, JDK support and our own usage counts, and builds part of the estate on the next JDK early. A library that falls behind goes on a watch list and then a planned migration.
Finally, the approved list and its reasons go into the testing standard, with a lightweight process for additions and a yearly review.
About this answer
- Last updated
- 12 November 2026
- 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 "Testing libraries come and go: JMock, EasyMock, PowerMock and JMockit were once popular...": https://scrivio-interview-library.netlify.app/java/mocking/76ec2f1dfa/