Quality Metrics and Test Reporting Questions
Defining, computing, and communicating software quality. Covers choosing meaningful quality and test metrics (defect escape rate, defect detection effectiveness, defect density, MTTD/MTTR, pass rate, regression frequency, automation suite health and maintenance cost) versus vanity numbers; baselining, trend interpretation (real change versus normal variation), and alert thresholds; dashboards, weekly stability reports, and release-quality reports for engineering, product, and executive audiences, including composite go/no-go scores; framing unfavourable results; guarding against gamed metrics and reading what numbers such as code coverage or a high pass rate hide; investigating contradictory or shifting metrics and testing whether a quality signal really predicts customer outcomes; metric definitions, ownership, and governance; computing metrics from test-run and bug-tracker data (SQL and scripts); designing test-results reporting pipelines, storage schemas, real-time versus batch reporting, alerting, and failure fingerprinting and grouping for triage; and tying quality signals to product and business outcomes. Deciding what to automate and diagnosing individual flaky tests are covered elsewhere.
You suspect higher unit-test coverage reduces customer-reported defects. How would you test that claim with the data you have, and what would stop you from concluding causation?
Sample Answer
Direct answer
I would compare modules (or module-release pairs) on coverage versus customer defects after normalising for size and usage, then check that the relationship survives once code churn, complexity and team differences are accounted for. Even a clean correlation stays correlation: the design (before-and-after within modules, comparable groups) is what earns causal language, and a small sample earns none.
Step by step
- Choose the unit and window: module per release. Measure coverage at release time and count customer-reported defects for a fixed window afterwards (say 90 days), otherwise recent releases look better.
- Normalise the outcome: defects per 10,000 active users of that module, not raw counts.
- Correlate: use Spearman rank correlation, which replaces each value by its rank (1st, 2nd, 3rd...) and correlates the ranks, so one extreme module cannot dominate. The result, called rho, runs from -1 (more coverage always means fewer defects) through 0 (no pattern) to +1 (more coverage always means more defects). Then ask whether chance alone could produce that rho with so few modules: a permutation test shuffles the defect numbers randomly many times and counts how often a shuffled version is as strong as the real one. That fraction is the p-value, the chance of seeing a pattern this strong if there were really no link. A small p-value (conventionally under 0.05) means the pattern is unlikely to be luck.
- Control confounders: a confounder is a third factor that drives both coverage and defects and so fakes or hides a link (for example, a critical module gets both more tests and more attention, and also more change). Stratify (compare only modules with similar churn, for example high-churn with high-churn) or model by churn (lines changed), complexity, module age, team and criticality.
- Prefer within-module change (a more advanced design): find modules where coverage was raised deliberately and compare them with similar modules that did not change (a difference-in-differences comparison: change in the treated group minus change in the comparison group). Illustration with made-up numbers: modules that got a coverage push went from 4.0 to 2.5 defects per 10k users (a drop of 1.5); comparable modules with no push went from 3.0 to 2.7 (a drop of 0.3, which is what happens anyway). The estimated effect of the push is -1.5 - (-0.3) = -1.2 defects. Core to know for interviews: steps 1 to 4. Step 5 is a strong follow-up idea, not something to open with.
Worked example (8 modules, illustrative data; run as is)
What the code does, in plain language: ranks turns each list of numbers into ranks (tied values share the average rank). pearson is the ordinary correlation formula, and spearman applies it to the ranks. The loop then shuffles the defect column 10,000 times (with a fixed seed so the run is repeatable) and counts how often a shuffled pairing looks at least as strong as the real one. The last lines compare high-churn and low-churn modules.
import random
# module, unit-test line coverage %, code churn (lines changed last year, thousands), customer defects per 10k active users
modules = [
("auth", 85, 3, 1.0), ("billing", 80, 9, 4.0),
("search", 55, 4, 2.0), ("export", 50, 2, 0.5),
("reports", 70, 8, 3.5), ("profile", 60, 1, 0.5),
("notify", 45, 7, 3.0), ("admin", 40, 2, 0.5),
]
def ranks(xs):
order = sorted(range(len(xs)), key=lambda i: xs[i])
r = [0.0] * len(xs)
i = 0
while i < len(order):
j = i
while j + 1 < len(order) and xs[order[j + 1]] == xs[order[i]]:
j += 1
for k in range(i, j + 1):
r[order[k]] = (i + j) / 2 + 1
i = j + 1
return r
def pearson(a, b):
ma, mb = sum(a) / len(a), sum(b) / len(b)
num = sum((x - ma) * (y - mb) for x, y in zip(a, b))
den = (sum((x - ma) ** 2 for x in a) * sum((y - mb) ** 2 for y in b)) ** 0.5
return num / den
def spearman(a, b):
return pearson(ranks(a), ranks(b))
cov = [m[1] for m in modules]; churn = [m[2] for m in modules]; dfx = [m[3] for m in modules]
rho = spearman(cov, dfx)
rng = random.Random(7)
perm_hits = 0
for _ in range(10000):
shuffled = dfx[:]
rng.shuffle(shuffled)
if abs(spearman(cov, shuffled)) >= abs(rho):
perm_hits += 1
print("coverage vs customer defects: spearman rho = %.2f" % rho)
print("permutation p-value (10000 shuffles, seed 7) = %.3f" % (perm_hits / 10000))
print("churn vs customer defects: spearman rho = %.2f" % spearman(churn, dfx))
print("churn vs coverage: spearman rho = %.2f" % spearman(churn, cov))
for label, group in (("high churn (>=7k lines)", [m for m in modules if m[2] >= 7]),
("low churn (<=4k lines)", [m for m in modules if m[2] <= 4])):
print("%s: n=%d mean coverage=%.1f mean defects=%.2f" % (
label, len(group), sum(m[1] for m in group) / len(group), sum(m[3] for m in group) / len(group)))
coverage vs customer defects: spearman rho = 0.44
permutation p-value (10000 shuffles, seed 7) = 0.283
churn vs customer defects: spearman rho = 0.98
churn vs coverage: spearman rho = 0.36
high churn (>=7k lines): n=3 mean coverage=65.0 mean defects=3.50
low churn (<=4k lines): n=5 mean coverage=58.0 mean defects=0.90
Reading it honestly:
- rho 0.44 is the wrong direction for the hypothesis. It is positive, so in these 8 modules higher coverage went with MORE customer defects, not fewer. But the p-value of about 0.28 means that if there were no link, shuffling would give a pattern this strong roughly 28% of the time with only 8 points, so it is not evidence of anything either way.
- Churn is the real driver here. Churn tracks customer defects almost perfectly (rho 0.98).
- How the confounder hides a coverage benefit: the heavily changed modules (high churn, n=3) have mean coverage 65 and mean defects 3.50, while the lightly changed ones (low churn, n=5) have mean coverage 58 and 0.90. Teams test the busy, critical modules more (coverage rose only weakly with churn here, rho 0.36, which with 8 modules cannot be told apart from chance), and those same modules break most because they change most. Any coverage benefit is therefore buried under the churn effect, and only comparing modules of similar churn can reveal it.
- The data cannot say coverage does not help, and it certainly cannot say it does.
- Stratifying does not rescue the hypothesis on this data. Recomputed within groups, the rank correlation of coverage with customer defects is +1.0 among the 3 high-churn modules (n=3, meaningless) and +0.45 among the 5 low-churn modules, both still positive. So even holding churn roughly fixed there is no sign of a coverage benefit here. The positive sign is more plausibly reverse causation (teams add tests where defects already hurt) plus a tiny sample, which is why the stronger designs below matter.
What stops me concluding causation
- Confounding: churn, criticality and usage drive both tests and defects.
- Reverse causation: the arrow points the other way. Teams add tests after a module hurts them, so coverage rises where defects were.
- Coverage measures execution, not checking: a test that runs code without asserting anything raises coverage and catches nothing.
- Range restriction: the data covers only a narrow slice of possible values. If every module sits between 70% and 90%, there is little variation to correlate. This is one common reason a real project can see coverage and escape rate uncorrelated.
- Small sample and multiple looks: eight modules, tried against five metrics, will produce a lucky result.
- Different bugs escape: integration, configuration and data problems are not what unit tests target.
Stronger designs: difference-in-differences around a deliberate coverage push, or mutation testing (deliberately breaking code to see whether tests fail; if 100 small deliberate breaks are injected and the tests catch 60, the mutation score is 60%), which measures assertion strength better than coverage and is rarely asked about in interviews.
A team boasts 90 percent code coverage. What does that number tell you about quality, what does it hide, and what would you report beside it so stakeholders can judge test effectiveness fairly?
Sample Answer
Direct answer
Code coverage (the share of lines or branches, meaning the true and false sides of each decision, that tests execute) tells you what is definitely untested. It does not tell you what is well tested: a test that runs a line without checking anything counts the same as a strong one. So 90 percent is not proof of quality. Beside it I would report mutation score (the share of deliberately planted bugs that the tests catch), requirement and risk coverage, escape rate (the share of defects that reached customers), flaky rate (the share of tests that pass and fail on identical code) and the coverage of changed code. If you only have room for three, start with mutation score, escape rate and coverage of changed code; the rest are useful extras.
Structured elaboration
What it hides
- Executing code is not asserting on it: an assertion is the line in a test that checks a result (for example
assert fee(60) == 0), and tests with no assertions still produce coverage. - Boundaries and business rules: reaching an
ifsays nothing about whether the edge value is right. - What is missing: code never written for a requirement has no lines to cover.
- The uncovered 10 percent may be the riskiest part (error handling, payments).
- Generated code, trivial getters and tests written to hit the number can inflate it.
What to report beside coverage, and how to present it to non-technical stakeholders
| Measure | Plain-language meaning | Example line for a report |
|---|---|---|
| Mutation score | Would the tests notice a bug? | "Tests caught 2 of 2 seeded bugs in the shipping rules" |
| Requirement coverage | Share of requirements with at least one linked passing test | "36 of 40 requirements (90%) have a passing test; the 4 uncovered are low risk and listed" |
| Risk coverage | Rate each area high, medium or low risk, agree the testing depth for each, then report whether that depth was reached. Are the high-risk areas tested to the depth agreed? | "Payments and login: tested to the agreed depth. Reporting: light" |
| Session coverage | Which areas got exploratory testing sessions (time-boxed human exploration) | "6 of 8 planned sessions done; 2 areas not yet explored" |
| Escape rate and flaky rate | What actually got through, and how far the suite can be trusted | "2 critical escapes in 30 days; 3% of tests flaky" |
| Coverage of changed code | Are the new lines tested? | "Changed lines in this release: covered" |
Escape rate is defects found in production divided by all defects found for a release. Example: 12 defects found for a release, 2 of them in production, so 2 / 12 = 17 percent. Flaky rate is flaky tests divided by all tests; 30 flaky tests out of 1,000 is 3 percent.
Statement, branch and condition coverage are finer ways to count what code ran (a statement is one line, a branch is one side of an if, a condition is one true/false part inside an if). You do not need them for this question, only that "90 percent" usually means one of the first two. The point here is which numbers to place beside it.
Worked example
Save as mutation_demo.py. A mutant is a copy of the code with one small deliberate bug; a good suite "kills" it by failing. Mutation score is mutants killed divided by mutants created. The first suite runs both branches, so line and branch coverage are both 100 percent, yet it kills nothing.
# Original code and two hand-made "mutants" (small deliberate bugs)
def fee_original(total):
if total >= 50:
return 0
return 5
def fee_mutant_a(total): # wrong constant: free shipping now costs 5
if total >= 50:
return 5
return 5
def fee_mutant_b(total): # boundary bug: >= became >
if total > 50:
return 0
return 5
def suite_no_asserts(fee): # runs every line and both branches, checks nothing
fee(60)
fee(10)
def suite_basic_asserts(fee): # asserts the two obvious cases
assert fee(60) == 0
assert fee(10) == 5
def suite_with_boundary(fee): # adds the boundary value
assert fee(60) == 0
assert fee(10) == 5
assert fee(50) == 0
def survives(suite, fee): # True = the suite did NOT notice the bug
try:
suite(fee)
return True
except AssertionError:
return False
mutants = {"A wrong constant": fee_mutant_a, "B boundary": fee_mutant_b}
suites = {"no asserts": suite_no_asserts,
"basic asserts": suite_basic_asserts,
"asserts + boundary": suite_with_boundary}
for sname, suite in suites.items():
suite(fee_original) # every suite passes on the real code
killed = sum(not survives(suite, m) for m in mutants.values())
print("%-20s original passes; mutants killed %d of %d -> mutation score %d%%"
% (sname, killed, len(mutants), 100 * killed // len(mutants)))
Output:
no asserts original passes; mutants killed 0 of 2 -> mutation score 0%
basic asserts original passes; mutants killed 1 of 2 -> mutation score 50%
asserts + boundary original passes; mutants killed 2 of 2 -> mutation score 100%
Same coverage, three very different levels of protection. Even the second suite, with real assertions, misses the boundary bug at exactly 50.
Trade-offs and pitfalls
- A coverage target invites tests written for the number, not the risk.
- Prefer the trend and coverage of changed code over one global figure.
- Escape rate is the outcome; mutation score is a check on the tests themselves. Mutation runs are slow on big codebases, so run them on changed or critical modules.
Explain mean time to detect and mean time to restore for defects. Given three defects with detection delays of 2, 5 and 1 hours and fix durations of 8, 2 and 4 hours, compute both and say what you would change in testing or monitoring as a result.
Sample Answer
Direct answer
Mean time to detect (MTTD) is the average delay between a defect appearing (or being introduced or released) and someone or something noticing it. Mean time to restore (MTTR) is the average time from detection until service or behaviour is working again. For your numbers: MTTD is 8/3 = about 2.7 hours, and MTTR is 14/3 = about 4.7 hours.
Definitions (state the clock start and stop, or the number is meaningless)
- MTTD = sum of detection delays / number of defects. Clock: defect present, to first detection.
- MTTR = sum of restore durations / number of defects. Clock: detection, to restored. (Some teams start the clock at the moment the defect began instead; say which you use, because the two differ by exactly the detection delay.)
- Mean time to fix (a related measure): from when someone actually starts remediation to resolution. It differs from MTTR because MTTR includes any waiting time in the queue before work starts. Comparing the two shows whether delay is in doing the work or in getting started.
Computation
| Defect | Detection delay (h) | Fix duration (h) | Total exposure (h) |
|---|---|---|---|
| 1 | 2 | 8 | 10 |
| 2 | 5 | 2 | 7 |
| 3 | 1 | 4 | 5 |
| Sum | 8 | 14 | 22 |
MTTD = (2 + 5 + 1) / 3 = 8 / 3 = 2.67 hours
MTTR = (8 + 2 + 4) / 3 = 14 / 3 = 4.67 hours
Mean total exposure = 22 / 3 = 7.33 hours
The exposure line is the time users could have hit the defect. Averages hide the shape, so look at each row.
Mean versus median on these numbers. The mean is the sum divided by the count; the median is the middle value once the numbers are sorted. Fix times sorted are 2, 4, 8, so the median is 4 hours while the mean is 4.67. Detection delays sorted are 1, 2, 5, so the median is 2 hours while the mean is 2.67. The single 8-hour fix drags the mean up; the median says a typical fix took 4 hours. A percentile (for example the 90th) says "nine in ten defects were fixed within this many hours", which needs many more than three defects to mean anything.
What I would change
- Defect 2 was slow to detect (5 hours) but quick to fix (2 hours). The gap is in detection: I would ask why no test or alert caught it, then add an automated check or a monitor for that behaviour.
- Defect 1 was found quickly (2 hours) but took 8 hours to fix. The gap is in restoring: look at whether rollback was possible, whether the owner was reachable, and whether a feature flag (a switch that turns the feature off without a deploy) could have restored service sooner.
- With only three data points, I would not change strategy on the averages alone. This is a tiny sample, so I would track these over many defects and use the median as well as the mean.
Link to DORA. DORA (the DevOps Research and Assessment programme) currently publishes five software delivery metrics (dora.dev): change lead time, deployment frequency, failed deployment recovery time, change fail rate and deployment rework rate. Two relate directly. Failed deployment recovery time (how long it takes to recover after a deployment causes a failure in production; older DORA reports called it time to restore service, and it is essentially MTTR measured on production incidents) and change fail rate (the share of deployments that need immediate intervention, so it counts how often you need MTTR at all). MTTD has no DORA equivalent, but it feeds MTTR when the clock starts at the defect's start.
Pitfalls
- Means are skewed by one long incident; the median and a high percentile add honesty.
- Gaming: reclassifying, closing tickets early, or starting the clock late. Guard by using system timestamps (alert time, deploy time) rather than self-reported ones.
- Mixing severity: one hour on a cosmetic bug is not one hour on a payment bug; report by severity.
What is defect escape rate, and how do you calculate it? Last release 120 defects were logged: 30 found by QA before release, 70 by customers and 20 by operations afterwards. Work out the rate, say how it relates to defect leakage, and what you would conclude about risk and where to focus testing.
Sample Answer
Direct answer
Defect escape rate is the share of a release's defects that got past your pre-release testing and were found afterwards. It is defects found after release divided by all defects found for that release. For this release: 70 (customers) + 20 (operations) = 90 escaped out of 120 total, so the escape rate is 90 / 120 = 75%. That is high: only a quarter of known defects were caught before release.
Calculation, step by step
- Caught before release by QA (quality assurance testing): 30
- Escaped (found after release): 70 by customers + 20 by operations = 90
- Total logged for the release: 30 + 90 = 120
- Escape rate: 90 / 120 = 0.75, or 75%
- Its mirror, the defect detection percentage (share caught before release): 30 / 120 = 25%
- As a ratio of escaped to caught: 90 / 30 = 3.0, so three defects escaped for every one caught
Escape versus leakage
Teams use the two words loosely, so state your definition. A common split: escape means the defect reached production (users or operations); leakage means a defect slipped past the stage that should have caught it (for example found in system test when a unit test should have caught it), which you can measure at every stage. Every escape is a leak, but not every leak escapes. With this release's 120 defects: the 90 escapes reached production, so the escape rate is 90 / 120 = 75%. Now suppose 10 of the 30 defects QA caught were found in system test although a unit test should have caught them (an illustrative split). Those 10 leaked past the unit-test stage, yet they did not escape. Leakage from the unit stage is therefore 10 defects (a third of the 30 caught before release), while the escape rate is unchanged at 75%. Some organisations use leakage as a synonym for escape, so confirm the local convention before comparing numbers.
What I would conclude about risk
The known risk is high, but I would qualify it before acting:
- Severity: 85 cosmetic escapes and 5 critical ones are very different stories, even though both make 90 escapes (85 + 5). Split the rate by severity.
- Who found them: 70 by customers is customer-visible pain; 20 by operations may point to configuration (settings differing between environments) or environment gaps that QA tests do not reach, so treat that group separately.
- Under-counting: customers do not report everything, so 75% is a floor for customer-visible issues.
- Window: fix the measurement window (for example the first 30 days after release) so releases compare fairly.
Where to focus testing
Do not "test more everywhere". Take the 90 escapes and group them by component (a module or part of the product, such as checkout or search), severity and root cause: no test existed, a test existed but missed it, or the environment differed. If, for instance, most severe escapes cluster in one component, add tests and review effort there first. For the 20 operations-found defects, look at environment parity (making the test environment match production in versions, data and settings), configuration testing (checking the settings that change between environments) and monitoring.
Pitfalls
The rate is gamed by not logging defects, closing them as "works as intended", or downgrading severity; cross-check with support tickets and incident counts.
What quality and test metrics would you track for a delivery team, and for each one, what does it actually tell you and where can it mislead?
Sample Answer
Direct answer
Track a small balanced set: a few metrics about defects reaching users, a few about how fast and trustworthy the test signal is, and a couple about delivery health. For every metric, write down two things next to it: the decision it informs and the way it lies. A metric you cannot attach a decision to is decoration.
The set, what each tells you, and where it misleads
| Metric | What it tells you | Where it misleads |
|---|---|---|
| Defect escape rate (share of a release's defects found only after release) | How much the test effort is missing before users see it | Falls when customers stop reporting, or when defects get downgraded or never logged. Says nothing about severity unless you split it |
| Test pass rate | Whether the current build is healthy | Rises when tests are deleted, skipped, quarantined (parked outside the blocking set so their failures no longer count), or retried until green (rerun automatically until they happen to pass). A 100% pass rate on a weak suite is comfort, not safety |
| Flaky test rate (tests that pass and fail on the same code) | How much you can trust a red build | Hidden if retries are automatic. High flakiness makes teams ignore real failures |
| Feedback time (push to result) and per-test execution time | How long a developer waits | Averages hide the slow tail (see the worked example) |
| Change failure rate (deployments that cause a failure needing a fix, divided by all deployments) and recovery time (two of the DORA delivery metrics from the DevOps Research and Assessment programme; dora.dev now calls the recovery one failed deployment recovery time, the time to recover from a deployment that fails and needs immediate intervention, which replaced the older MTTR, mean time to restore service, and it also lists a fifth metric, deployment rework rate) | Whether fast delivery is coming at the cost of stability | Small deployments can make the rate look better while impact per failure grows. Averages hide one long outage |
| Open defects by severity and age | Release risk and neglected problems | A low count can mean nobody is looking. Severity labels are subjective |
| Customer-side signals (crash-free sessions, meaning the share of app sessions that end without a crash; support tickets per active user) | Product health as users experience it, the balance to engineering-side numbers | Lags by days or weeks and is affected by usage changes |
Code coverage (the share of code lines that tests execute) is a related signal that is deliberately left out of the table because it measures only whether code was executed, not whether any assertion checked the result (a test with no assertions still raises coverage). Use it as "where we definitely have no tests", never as proof of quality.
Quick numbers for the other rows (illustrative)
- Escape rate: a release has 40 defects logged in total, 30 found before release and 10 found by customers afterwards. Escape rate = 10 / 40 = 25%.
- Pass rate and quarantine: 1,000 tests run, 50 fail, so 950 / 1,000 = 95%. If 30 of the failures are quarantined and excluded, the report shows 950 / 970 = 97.9%. The number rose although nothing was fixed, which is why quarantined counts must be shown beside it.
- Flaky test rate: 12 of 400 tests both passed and failed on the same code this week, so 12 / 400 = 3%.
- Change failure rate: 6 of 40 deployments this month needed a fix or rollback, so 6 / 40 = 15%.
- Crash-free sessions: 9,900 of 10,000 sessions ended without a crash, so 99%. Note that 99% still means 100 crashed sessions.
Worked example: throughput and execution time under parallelism
A suite has 1,200 tests averaging 2 seconds each, so 2,400 seconds of compute. Split across 4 parallel machines (shards) the ideal wall-clock time is 2,400 / 4 = 600 seconds. In practice the shards are uneven: if the slowest takes 900 seconds, the run takes 900 seconds, not 600. Add 5 minutes (300 seconds) waiting in the queue for a free runner and a developer waits 1,200 seconds, 20 minutes, even though "average test time" is still 2 seconds. Retries also distort: if 3% of tests (36) are retried, that adds 36 x 2 = 72 seconds of compute, invisible in the average but visible as extra cost and hidden flakiness. So report feedback time end to end and its 95th percentile (the value 95% of runs come in under), plus retry count, not only average per-test time or tests per hour.
Thresholds and balance
There are no honest universal numbers. Set thresholds against your own baseline and act on direction: escape rate rising two releases in a row, flake rate creeping up, feedback time past what developers will wait for (they start skipping it). Read product and engineering metrics together: fast feedback with rising escapes means the fast tests are the wrong tests; falling escapes with falling customer usage proves nothing.
Gaming and pitfalls
Every row above can be gamed (delete tests, downgrade severity, retry to green). Prefer trends over targets, publish denominators, and never rank individuals with these numbers.
Unlock Full Question Bank
Get access to all 32 Quality Metrics and Test Reporting interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.