Quick revision
The short answer
I would collect at the platform level, either with a shared TestExecutionListener in a company test library or by uploading the JUnit XML and Open Test Reporting files every build already writes, and send one compact event per test execution (repository, commit, branch, test id, duration, result, retry attempt, environment) to a central store. Flakiness is a test that both passed and failed on the same commit; slowest tests and failure clusters come from queries over that data. We keep secrets out by not sending test output by default, control cost with sampling and retention, and turn the data into team dashboards and automatic tickets for the worst offenders.
What to remember
In this answer, we designed organisation-wide test analytics by collecting at the JUnit Platform level, through uploaded JUnit XML and Open Test Reporting files and optionally a shared TestExecutionListener, and converting everything into one compact event per execution with repository, commit, test id, duration, result and retry attempt. Flakiness is a test that both passed and failed on the same commit, slowness comes from duration percentiles and trends, and clusters come from failure fingerprints. We kept secrets out by not sending output, controlled cost with sampling and retention, and closed the loop with team dashboards and automatic tickets.
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 collect at the platform level, either with a shared TestExecutionListener in a company test library or by uploading the JUnit XML and Open Test Reporting files every build already writes, and send one compact event per test execution (repository, commit, branch, test id, duration, result, retry attempt, environment) to a central store. Flakiness is a test that both passed and failed on the same commit; slowest tests and failure clusters come from queries over that data. We keep secrets out by not sending test output by default, control cost with sampling and retention, and turn the data into team dashboards and automatic tickets for the worst offenders.
Why this question is asked
With 300 repositories, every team sees only its own builds, and nobody can answer simple organisation-wide questions: which tests are flaky, which are slowest, whether a failure in ten repositories is the same failure. Test analytics answers those questions, but only if the data is collected the same way everywhere and turned into action. Interviewers ask this design question to see whether we can design a pipeline end to end, collection, transport, storage, analysis and feedback, and whether we think about privacy and cost. In this answer, we will choose where to collect, define the event, store it, compute the three metrics, protect secrets and budget, and close the loop with dashboards and tickets.
1Where to Collect the Data
There are two good places, and both sit at the JUnit Platform level, so they work for every engine and every build tool. The first is the reports that already exist. Maven Surefire and Failsafe and Gradle all write JUnit XML files with one entry per test case, its time, and any failure or skip, and Surefire records flaky reruns too. JUnit itself can write the Open Test Reporting format, which carries more structure, such as unique ids and tags. A shared CI step that uploads these files after every build needs no change inside any test JVM.
The second is a TestExecutionListener in a company test library, registered through META-INF/services so that every repository using the company parent POM or Gradle convention plugin gets it. It sees events live, can add data the reports lack, such as tags and the exact unique id, and can send events even when a build is killed halfway through.
In practice I would start with report uploads, because they work on day one for all 300 repositories with a single CI template change, and add the listener later where richer data is worth it.
2Defining One Event per Test Execution
Every source is converted into the same small event. It must identify the test stably across runs, place it in time and code, and record what happened. Keeping it small matters, because 300 repositories with an average of 3,000 tests and 20 builds a day produce about 18 million events a day.
- Builds in 300 repositoriesJUnit XML, Open Test Reporting, shared listener
- CI upload stepconvert to events, drop output, add repo and commit
- Ingestion queueabsorbs bursts, retries on failure
- Event storecolumnar tables partitioned by day
- Jobs and queriesflaky detection, slowest tests, clusters
- Dashboards and ticketsper team, top offenders
6 layers, from the top down. Step through them one at a time.
Notice the attempt field. Without it, a retried test that passed looks like a pass, and the flaky signal is lost. Notice also that we send a fingerprint of the failure, not the full message and output. That is part of the privacy design below.
3Computing Flakiness, Slowness and Failure Clusters
Flakiness has a precise definition we can compute: a test is flaky on a commit if it both passed and failed on that same commit, either through retries in one build or across reruns of the build. Code did not change, so the difference came from the test or the environment. The flaky rate of a test is the share of commits in the last 30 days on which it was flaky. Failures on a commit with no pass are treated as real failures, not flakiness.
Slowest tests are a simple aggregation: median and 95th percentile duration per test over the last week, ranked within each repository and across the organisation. Watching the trend matters as much as the rank; a test that went from 1 second to 20 seconds last Tuesday points at a specific change.
Failure clustering groups failures by their fingerprint. When 40 tests in 12 repositories fail on the same morning with the same exception type and top frames, for example a connection refused to a shared test database, that is one incident, not 40 problems. Grouping by fingerprint, runner type and time window shows it immediately and sends it to the platform team instead of 12 product teams.
| Metric | Rule | Who acts |
|---|---|---|
| Flaky rate | passed and failed on the same commit | owning team, via ticket |
| Slowest tests | p50 and p95 duration per test, trend | owning team, budget review |
| Failure clusters | same fingerprint across repos in a window | platform team, as an incident |
4Privacy and Cost
Test output is dangerous to collect. Logs and failure messages can contain tokens, connection strings, customer-like data from fixtures, or personal data in a test that used a production copy. So the default is to send no stdout, no stderr and no raw failure messages, only the exception type and a fingerprint of the top stack frames, which are code locations, not data. If a team wants messages for debugging, they stay in that repository's own CI artifacts, where access is already controlled. A scrubber that masks anything shaped like a secret is a second line of defence, not the first.
Cost comes from volume. Passing runs of fast, stable tests are most of the events and carry the least information, so we can sample them, for example keep 10 percent of successful unit test events on feature branches, while keeping every failure, every retry and every main-branch build. Retention follows the same idea: detailed events for 90 days, daily aggregates for two years. With columnar storage and those rules, 18 million events a day stays a modest bill.
5Closing the Loop With Dashboards and Tickets
Data that nobody looks at changes nothing. Each team gets a dashboard of its own repositories: flaky tests with their rate, the slowest tests with trends, and its share of the organisation's failure clusters. A weekly job opens or updates a ticket in the owning team's tracker for the top offenders, for example any test with a flaky rate over 2 percent or a p95 duration over its tier's budget, with a link to the evidence. Organisation-wide numbers go to the engineering quality review, so improving them can be planned. Rolling out in stages, five pilot repositories first, then everyone through the shared CI template, lets us fix the event format before it becomes a contract.
6Follow-up questions
Why compute flakiness per commit instead of just counting failures?
Because a failure count mixes real regressions with flakiness. A test that fails on every build after a bad commit is doing its job. Only a test whose result changes while the code stays the same is flaky, and the same commit is the simplest reliable way to hold the code constant.
Would you build or buy this?
It depends on scale and budget. Commercial test analytics products, often part of build acceleration platforms, offer flaky detection and dashboards out of the box. The design above is still how I would evaluate them: does it work at the platform level for every build tool, does it record retries, can we keep output out, and does it push tickets to teams.
7Conclusion
In this answer, we designed organisation-wide test analytics by collecting at the JUnit Platform level, through uploaded JUnit XML and Open Test Reporting files and optionally a shared TestExecutionListener, and converting everything into one compact event per execution with repository, commit, test id, duration, result and retry attempt. Flakiness is a test that both passed and failed on the same commit, slowness comes from duration percentiles and trends, and clusters come from failure fingerprints. We kept secrets out by not sending output, controlled cost with sampling and retention, and closed the loop with team dashboards and automatic tickets.
Open with
I would collect at the JUnit Platform level so it works for every engine and build tool. The quickest start is the reports every build already writes, JUnit XML from Surefire, Failsafe and Gradle, and Open Test Reporting where it is enabled.
Then, if they want more
A shared CI step uploads them after each build, so all 300 repositories are covered by one template change. Where we need richer or live data, I would add a TestExecutionListener in a company test library, registered through META-INF/services and pulled in by the parent POM or convention plugin.
Every source becomes one small event: repository, commit, branch, build, runner, test unique id, tags, duration, status and the retry attempt, plus a fingerprint of the exception type and top frames rather than the message. Events go through a queue into a columnar store partitioned by day.
Then the metrics: a test is flaky when it both passed and failed on the same commit, slowest tests come from p50 and p95 durations and their trend, and clusters come from grouping fingerprints across repositories in a time window, which usually points at shared infrastructure.
For privacy I would send no test output by default, because it can contain secrets. For cost, I would sample passing runs on feature branches and keep failures and main-branch builds in full. Finally, teams get dashboards and automatic tickets for their worst tests, and the numbers go to the quality 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
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 "You want organisation-wide test analytics (flaky rate, slowest tests, failure...": https://scrivio-interview-library.netlify.app/java/junit/c24dec1ae3/