Quick revision
The short answer
We publish the test cases once, as shared data files or ArgumentsProvider classes in a versioned test library, and each service runs those shared cases against its own implementation. Better still, if the rule is truly the same everywhere, we move the rule itself into one shared library that is tested once. Either way the shared cases are versioned, so a newly found edge case reaches every service through a normal dependency upgrade.
What to remember
In this answer, we saw that copied parameterized tests drift and let the same bug ship repeatedly. Publishing the cases once, as data files and ArgumentsProvider classes in a versioned test library, lets each service run them against its own implementation and shows where implementations disagree. When the rule is stable and universal, we go further and share the rule itself, tested once. Versioning and automated dependency updates make new edge cases reach every service.
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.
We publish the test cases once, as shared data files or ArgumentsProvider classes in a versioned test library, and each service runs those shared cases against its own implementation. Better still, if the rule is truly the same everywhere, we move the rule itself into one shared library that is tested once. Either way the shared cases are versioned, so a newly found edge case reaches every service through a normal dependency upgrade.
Why this question is asked
Copied tests drift. One team finds that a Saint Lucia IBAN breaks their validator and adds a case; the other seven teams never hear about it, and the bug ships seven more times. Interviewers ask this design question to see whether we treat test cases as shared knowledge and whether we notice that duplicated tests often point to duplicated logic. In this answer, we will look at why copies drift, publish shared cases in a test library, wire them into each service, consider moving the rule itself, and set up versioning so new cases spread.
1Why Copied Test Cases Drift
Validation rules such as ISO 4217 currency codes, IBAN check digits and country postal formats are the same rules for everyone, but each team copied the parameterized test once and then maintained its copy alone. Over time the copies diverge: one has 40 IBAN cases, another 12, a third still contains a case for a currency code that was withdrawn. Nobody knows which copy is the best one.
The real knowledge in those tests is the list of cases, especially the tricky ones that someone learned about from a production incident. That list is what we want to share.
2Publishing the Cases in a Shared Test Library
We create a small library, for example validation-test-cases, published to our artifact repository and added to services with test scope. It contains the cases in one of two forms. Data files, such as CSV or JSON on the classpath, are easy for non-developers to review and can be used from other languages too. ArgumentsProvider classes are type-safe and can build richer objects. A common approach is both: the data in files, and a provider that reads them.
Each row has a reason column, which becomes the display name. When a service fails a case, the report says wrong check digits rather than row 3, and the person who sees it knows what rule they broke.
3Running the Shared Cases in Each Service
Each service keeps its own implementation for now, so each service writes one small test that feeds the shared cases into its own validator. The shared library provides the cases; the service provides the code under test.
- validation-test-cases libraryCSV files and
ArgumentsProviderclasses, versioned - Each service's test
@ArgumentsSourcefeeds the shared cases - Each service's validatorits own implementation under test
3 layers, from the top down. Step through them one at a time.
Notice that this works even for services in other languages, as long as they read the same CSV files; the Java provider is only a convenience. The first run often fails in some services, which is exactly the point: it shows where implementations already disagree.
4Better Still: Share the Rule Itself
If eight services must all validate IBANs identically, eight implementations are the real problem; shared tests only make the duplication visible. The stronger fix is to move the rule into one shared library, for example validation-rules, and test it once with the full set of cases. Services depend on the library and test only how they use it, for example that the payment endpoint rejects an invalid IBAN with a 400.
This has its own costs: a shared library couples services to its release cycle, and a bug in it affects everyone at once. So it suits rules that are stable and universal, such as check digit algorithms and ISO code lists. Rules that legitimately differ per service, for example which countries a product supports, should stay local, perhaps with shared cases for the common part.
| Option | Cost | Best when |
|---|---|---|
| Copied tests (today) | cases drift, bugs repeat | never, as a long-term state |
| Shared cases, own code | each service still maintains code | implementations must differ |
| Shared rule library | coupling to one release | rule is stable and universal |
5Versioning So New Edge Cases Reach Everyone
The shared cases need a version, like any library. When someone finds a new edge case, they add a row and release a new minor version. Services pick it up through their normal dependency updates, and a tool such as Renovate or Dependabot opens the upgrade pull request automatically. If a service fails the new case, the pull request shows it, and the team fixes the validator or records a deliberate difference.
A changelog that says what each new case covers helps teams understand failures, for example 1.4.0 adds IBANs with lowercase letters. Removing or changing an existing case is a breaking change and deserves a major version, because it changes what counts as correct.
6Follow-up questions
Who owns the shared test cases?
One named team, often the team that knows the domain best, such as payments for IBANs, with contributions from everyone through pull requests. Without an owner, the library becomes another copy that nobody maintains.
What if a service legitimately needs a different answer for one case?
It should record that difference explicitly, for example with a small list of excluded case names and a comment explaining why, rather than silently deleting rows from a copy. That keeps the difference visible when the rule is reviewed.
Why not just use a third-party validation library?
Often that is the best rule library: for IBANs or ISO codes a well-maintained open source library may already exist. The shared test cases are still useful, because they record the cases our business cares about and protect us when we upgrade that library.
7Conclusion
In this answer, we saw that copied parameterized tests drift and let the same bug ship repeatedly. Publishing the cases once, as data files and ArgumentsProvider classes in a versioned test library, lets each service run them against its own implementation and shows where implementations disagree. When the rule is stable and universal, we go further and share the rule itself, tested once. Versioning and automated dependency updates make new edge cases reach every service.
Open with
I would stop copying the tests and publish the cases once. I would create a small test library, owned by the team that knows the domain, with the cases as data files, for example a CSV per rule with input, expected result and a reason column, plus ArgumentsProvider classes that read them.
Then, if they want more
Each service adds it as a test dependency and writes one parameterized test with @ArgumentsSource that runs the shared cases against its own validator, using the reason as the display name so failures are readable. The first run usually shows that some services already disagree, which is useful.
But I would also point out that eight copies of IBAN validation is the real problem. If the rule is stable and universal, like check digits or ISO currency codes, I would move the rule itself into one shared library, test it once with all the cases, and have services only test how they use it.
Rules that legitimately differ stay local. Either way, I would version the cases like any library: a new edge case means a new minor release with a changelog entry, Renovate or Dependabot opens upgrade pull requests, and a failing case shows up in that pull request rather than in production.
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
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 "Several teams test the same validation rules (currency codes, IBANs, country formats)...": https://scrivio-interview-library.netlify.app/java/junit/ece9b63634/