Quick revision
The short answer
I would treat the library as a product with a named owner, semantic versioning, a changelog and a deprecation policy, and shrink its public surface to a few composed annotations and documented extension points. Every release is tested against representative consumer projects before it ships. Over time we remove features that JUnit or Spring now provide, with migration guides, and we prepare for JUnit major versions by testing their early releases.
What to remember
In this answer, we saw that a shared test library used by 200 services becomes hard to change because every behaviour is depended on. We managed it as a product with an owner, semantic versioning, changelogs and a deprecation policy, kept the public surface to a few composed annotations and extension points, tested every release against representative consumer projects, removed features that JUnit and Spring now provide with migration guides, and tested early JUnit major releases so the library is ready before teams upgrade.
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 treat the library as a product with a named owner, semantic versioning, a changelog and a deprecation policy, and shrink its public surface to a few composed annotations and documented extension points. Every release is tested against representative consumer projects before it ships. Over time we remove features that JUnit or Spring now provide, with migration guides, and we prepare for JUnit major versions by testing their early releases.
Why this question is asked
A shared test library used by 200 services is a success that becomes a trap: every behaviour, documented or not, is something some team relies on, so every change risks breaking builds across the company. This is Hyrum's law in action, the observation that with enough users every observable behaviour of a system will be depended on by somebody. Interviewers ask this leadership question to see whether we can keep a widely used internal library healthy for years. In this answer, we will see why it became hard to change, set up ownership and versioning, shrink the public surface, test against consumers, retire duplicated features and plan for JUnit major versions.
1Why the Library Became Hard to Change
Libraries like this usually grow by accretion. A team needed a helper, added it, and it shipped to everyone. After five years the library has dozens of extensions, utility classes, base classes and hidden defaults, and nobody knows which of them the 200 services use. Some teams depend on behaviour that was never intended, for example the order in which two extensions run, or a side effect of a cleanup step. Since there is no clear line between public API and internals, any change might break someone, so people stop changing it at all.
2Treating It as a Product
The first step is ownership. A named team owns the library, with time budgeted for it, a backlog, and a channel where users ask questions. Without an owner, every change is someone's side project and quality drifts.
Next, semantic versioning with real meaning: a patch release fixes bugs, a minor release adds features without breaking anything, and a major release may break things and comes with a migration guide. Every release has a changelog entry written for users, explaining what changed and what they need to do. A deprecation policy sets expectations, for example that a deprecated feature is marked with @Deprecated and a log warning in one minor release, and removed no earlier than the next major release, at least six months later.
3Keeping the Public Surface Small
The more a library exposes, the more it must keep stable. So we define the public surface explicitly: a few composed annotations, such as @ServiceTest, and a few documented extension points, such as an interface teams can implement to add their own cleanup. Everything else moves into internal packages. With Java modules or a build check, such as ArchUnit, a library that tests architecture rules, we can stop consumers from importing internal packages.
- Public: composed annotations
@ServiceTest,@DomainTest, stable for a major version - Public: documented extension pointssmall interfaces, such as
CleanupStrategy - Internal packagesfree to change; imports blocked by a build check
3 layers, from the top down. Step through them one at a time.
To find what teams actually use, we can scan the 200 repositories for imports of the library's classes. This tells us which features are widely used, which are used by one service, and which are not used at all. Unused ones can be removed in the next major version; features used by one service can move into that service.
4Testing Against Representative Consumers
Unit tests of the library are not enough, because the risk lies in how consumers use it. So we keep a set of representative consumer projects: a few real services, chosen to cover the main shapes, such as a web API, a Kafka consumer and a batch job, plus small sample projects. Before each release, CI builds a snapshot of the library and runs those projects' test suites against it. A release that breaks a consumer does not ship until the break is fixed or documented as intended in a major version.
- Change merged into the library
- Build a snapshot
- Run consumer test suites against itweb API, Kafka consumer, batch job, samples
- Any consumer broken?YesFix, or move the change to a major versionNoWrite changelog and release
- Renovate opens upgrade PRs in all services
5 steps in order. Play them, or step through them one at a time.
5Removing What JUnit or Spring Now Provide
Many helpers in an old test library were written before the framework had the feature. Temporary directories are now JUnit's @TempDir; Spring Boot provides test slices, @MockitoBean (replacing @MockBean in recent versions; check your version), Testcontainers integration with @ServiceConnection, and @DynamicPropertySource. Keeping our own versions means maintaining code the framework already maintains for us, and newcomers learn our variant instead of the standard one.
So we deprecate duplicates with a migration guide that shows the old and new code side by side, and where possible an automated migration, for example an OpenRewrite recipe that rewrites our annotation into the framework's. Removing features is how the library stays small enough to change.
6Planning for JUnit Major Versions
A major JUnit release, like the move from JUnit 5 to JUnit 6, can remove APIs our extensions use. Because 200 services depend on the library, we should not discover that on the release day. We run the library's build and the consumer projects against JUnit milestones and release candidates as they appear, fix our extensions early, and publish a library version that supports the new JUnit before teams start upgrading. The same applies to Spring Boot major versions, which change test support too.
7Follow-up questions
How do you convince teams to upgrade to the new major version?
By making it cheap: a clear migration guide, automated recipes for the mechanical changes, support from the owning team during a fixed window, and a stated end date for patches on the old major version. Tracking which services are on which version on a dashboard also shows progress and finds the teams that need help.
What if one team depends on undocumented behaviour you need to change?
I would talk to them first, understand why they depend on it, and either offer a documented way to get the same result or keep the behaviour behind an explicit option during a transition. Then the change goes into a major version with a note in the changelog, so it is never a surprise.
How do you decide what belongs in the library at all?
A feature belongs there if several teams need it, it is stable and it fits the library's purpose. Something only one or two services need stays in those services, even if it is well written, because every shared feature adds to what the library must keep stable for everyone.
8Conclusion
In this answer, we saw that a shared test library used by 200 services becomes hard to change because every behaviour is depended on. We managed it as a product with an owner, semantic versioning, changelogs and a deprecation policy, kept the public surface to a few composed annotations and extension points, tested every release against representative consumer projects, removed features that JUnit and Spring now provide with migration guides, and tested early JUnit major releases so the library is ready before teams upgrade.
Open with
I would start by making it a product instead of shared code nobody owns. A named team owns it with real time for it, and we use semantic versioning with a changelog written for users and a deprecation policy, for example deprecate in a minor release with a warning and remove no earlier than the next major, at least six months later.
Then, if they want more
Then I would shrink the public surface. I would scan all 200 repositories to see which classes they actually import, keep a few composed annotations and documented extension points as the public API, move everything else to internal packages and block imports of them with a build check.
Unused features go in the next major version, and features only one service uses move into that service. Before every release I would run a set of representative consumer projects, a web API, a Kafka consumer, a batch job and some samples, against a snapshot, so we find breaks before 200 builds do.
I would also remove things JUnit and Spring now give us, like @TempDir, test slices and Testcontainers service connections, with migration guides and OpenRewrite recipes where possible. And for JUnit or Spring Boot major versions, I would test against milestones early so the library is ready before teams upgrade.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- 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
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 shared test library of JUnit extensions is used by 200 services and has become hard...": https://scrivio-interview-library.netlify.app/java/junit/feeb06fe80/