Test system metrics
Test system metrics answer three questions: is feedback fast, do we trust the result, do we catch what matters. They are pipeline time by p50 and p95, flaky rate, pass rate on main and escaped defects. An average hides the tail of slow runs, and a metric turned into a target starts to be distorted, so metrics are read together and code coverage is not treated as quality.
System design · Metrics
The average run takes 10 minutes, yet developers complain about 25. Who is right?
The dashboard shows "average pipeline time 10 minutes", and it seems all is well. But every fifth run takes 25 minutes because of a slow shard, and these are the runs developers remember. Metrics exist to see such things before complaints, but a wrong metric is worse than none: it creates a calm that is not there. The lesson covers what to measure in a test system, how to compute it and what not to measure.
How it works and why. Test system metrics answer three questions: is feedback fast, do we trust the result, do we catch what matters. Speed: pipeline time. Trust: flaky rate and pass rate on main. Effectiveness: escaped defects, that is bugs that reached production. Each metric is tied to a decision: if the number changes, what do we do differently? A metric without a decision is decoration.
| Metric | What it shows | Starting reference |
|---|---|---|
| Pipeline time p50 and p95 | Feedback speed | PR within 10-15 min |
| Flaky rate | Share of tests that passed only on a retry | Below 1-2 percent |
| Pass rate on main | Health of the main branch | Close to 100 percent |
| Escaped defects | Bugs found in production | Trend down |
| Time to investigate a failure | How long analysis takes | Trend down |
| Cost of a run | CI spend | Under control |
The references are a starting point, not an industry standard: they are chosen for the team and checked for whether they really influence decisions.
Why p95 and not the average. The average mixes fast and slow runs into one number. The p95 percentile says: 95% of runs are faster than this value, so the remaining 5% is the tail. Developers feel exactly the tail: every slow run is a stalled PR.
One sample, two numbers
10 minutes
Looks fine. Hides that a part of the runs is slow.
25 minutes
Shows the tail: this is the delay the team feels.
Example: computing flaky rate and p95 from a JSON report. The Playwright JSON reporter stores a final status for every test (expected, unexpected, flaky, skipped). A small script turns the file into two metrics:
type Suite = { suites?: Suite[]; specs?: { tests: { status: string }[] }[] };
const statuses = (s: Suite): string[] => [
...(s.specs ?? []).flatMap((sp) => sp.tests.map((t) => t.status)),
...(s.suites ?? []).flatMap(statuses),
];
const p95 = (xs: number[]) => {
const sorted = [...xs].sort((a, b) => a - b);
return sorted[Math.ceil(sorted.length * 0.95) - 1];
};
const all = report.suites.flatMap(statuses);
const flakyRate = all.filter((s) => s === 'flaky').length / all.length;
console.log('flaky rate', (flakyRate * 100).toFixed(1) + '%');
console.log('pipeline p95', p95(pipelineMinutes), 'min');
(report is the parsed results.json, pipelineMinutes is an array of run durations from CI.) Metrics make sense over weeks of history, not one run: a single run is an anecdote, a trend is data.
Escaped defects: the most honest metric. Every production bug is worth analysing with three questions: could a test have caught it, at which level (unit, API, e2e, manual check) and why it did not. The answers give concrete actions: add a check at a lower level, fix the data, update a checklist. This is more useful than the abstract "increase coverage".
Limits and alternatives. Code coverage shows that lines were executed, not what was verified: a test without meaningful assertions also gives coverage. For e2e, coverage of business risks is more useful: all payment methods, currencies, transfer statuses. A metric turned into a target (for example, "flaky rate below 1%") starts to distort: tests are simply deleted or hidden in quarantine. So metrics are read together: a falling flaky rate must come with a steady number of tests and escaped defects. For feedback speed a separate metric helps too: time from commit to the first red result.
Common mistakes.
- Looking only at average time: the tail is what developers feel.
- Counting code coverage as quality: a high percentage without checks guarantees nothing.
- Metrics on a single run: they jump and show no trend.
- A target on a metric without watching side effects: a falling flaky rate because tests were deleted.
Check yourself
There are 100 runs: 90 at 8 minutes and 10 at 40 minutes. Why does the average (11.2 min) mislead and what does p95 show?
Answer
The average smears slow runs over the whole sample and looks acceptable. p95 is the value below which 95% of runs fall: here it is about 40 minutes, because the slow runs are 10% of the sample. This delay stalls PRs, so p95 reflects the team's experience better.
The team set a goal "flaky rate below 1%" and in a month it fell to 0.3%. What else to check before celebrating?
Answer
Whether the number of tests fell, whether unstable tests were moved to quarantine without a fix, whether escaped defects and investigation time are growing. If the numbers improved by removing coverage, the goal was met formally while quality fell.