Scrivio Interview library
DesignAdvanced5 min read · updated 12 November 2026

Several teams test the same validation rules (currency codes, IBANs, country formats) with copied parameterized tests. How would you share test cases across services?

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.

Text
# src/main/resources/cases/iban.csv in validation-test-cases
input,valid,reason
GB82WEST12345698765432,true,valid UK IBAN
DE89370400440532013000,true,valid German IBAN
GB82WEST12345698765433,false,wrong check digits
GB82 WEST 1234 5698 7654 32,true,spaces allowed in display format
XX00123,false,unknown country code

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.

Java
// In the shared library
public class IbanCases implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return CsvCases.read("/cases/iban.csv")
.map(r -> Arguments.of(Named.of(r.get("reason"), r.get("input")), Boolean.parseBoolean(r.get("valid"))));
}
}
// In the payments service
class PaymentsIbanTest {
@ParameterizedTest(name = "{0}")
@ArgumentsSource(IbanCases.class)
void validatesIban(String input, boolean valid) {
assertEquals(valid, paymentsIbanValidator.isValid(input)); // the service's own code
}
}
Step throughShared cases, separate implementations
  1. validation-test-cases libraryCSV files and ArgumentsProvider classes, versioned
  2. Each service's test@ArgumentsSource feeds the shared cases
  3. 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.

Options for shared validation
OptionCostBest when
Copied tests (today)cases drift, bugs repeatnever, as a long-term state
Shared cases, own codeeach service still maintains codeimplementations must differ
Shared rule librarycoupling to one releaserule 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.

What to say in the interviewAbout 80 seconds aloud

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/