Measuring how much testing you have done, and how much is left.
π Where this lives: "are we ready to release?" is a question somebody has to answer with a date attached, and testing metrics are the only evidence available. But they are also the most gamed numbers in software: a team told to hit 80% coverage will hit 80% coverage, and whether that means anything depends entirely on how the target was set. Goodhart's law β "when a measure becomes a target, it ceases to be a good measure" β was practically written for this topic. Search "Goodhart's law software metrics gaming code coverage".
What to measure
Testing metrics fall into three families, answering three
different questions.
1. COVERAGE METRICS β how much of the system has been
exercised?
statement coverage = statements executed / total
branch coverage = branches taken / total branches
condition coverage = conditions evaluated both ways /
total
function coverage = functions called / total
requirements = requirements with at least one
coverage test / total requirements
path coverage = paths executed / total (rarely
computable)
2. DEFECT METRICS β what have we found, and what is left?
DEFECT DENSITY = defects found / size
(per KLOC, or per function point)
DEFECT REMOVAL DRE = E / (E + D)
EFFICIENCY where E = errors found BEFORE delivery
and D = defects found AFTER delivery
β DRE = 1 is the ideal. This is
probably the single most useful
process metric in this topic, because
it measures the thing you actually
care about: did we catch it, or did
the customer?
DEFECT LEAKAGE defects that escaped from one phase to
the next
defect arrival rate, and the DEFECT DISCOVERY CURVE
(below)
MTTD / MTTR mean time to detect / to repair
3. EFFORT AND PROGRESS METRICS
test cases planned / executed / passed / failed / blocked
test execution rate (tests per day)
automation percentage
test effort as a fraction of total project effort
mean time between failures (MTBF), for reliability
RELIABILITY METRICS, since they are what a customer actually
experiences:
POFOD probability of failure on demand β the likelihood
the system fails when a service request is made.
Right for systems where each demand matters
(a safety shutdown).
ROCOF rate of occurrence of failures β failures per unit
time. Right for transaction systems.
MTTF mean time to failure. The reciprocal of ROCOF, for
long-running systems.
AVAIL availability = MTBF / (MTBF + MTTR) β the metric
from the architecture topics.
Worked: reading a test report
A REAL-SHAPED SET OF NUMBERS from a system test cycle on the
licence system.
total test cases planned 860
executed 742
passed 651
failed 74
blocked (cannot run β a defect
prevents reaching the case) 17
not yet executed 118
defects found this cycle 91
defects fixed and verified 58
defects open 33
code size 32.4 KLOC
statement coverage 78%
branch coverage 61%
DERIVED METRICS β compute them all:
TEST EXECUTION PROGRESS
= executed / planned = 742/860 = 86.3%
TEST PASS RATE
= passed / executed = 651/742 = 87.7%
TEST EFFECTIVENESS (defects per executed test)
= 91/742 = 0.123
β about 1 defect per 8 tests
DEFECT DENSITY
= 91 / 32.4 = 2.81 per KLOC
DEFECT FIX RATE
= 58/91 = 63.7%
BLOCKED RATE
= 17/742 = 2.3%
NOW READ THEM, because the numbers only matter interpreted:
Β· 86.3% executed with 118 cases outstanding: the cycle is
NOT complete, so the pass rate is provisional. Untested
areas are where the remaining defects are.
Β· 87.7% pass rate sounds healthy, but 74 failures against
91 defects means most failures are distinct defects rather
than repeats of one β the failures are SPREAD, not
clustered, which suggests systemic rather than local
problems.
Β· THE MOST IMPORTANT NUMBER IS THE COVERAGE GAP:
78% statement but only 61% branch. That 17-point spread
says that many decisions have been executed one way only β
the error paths, precisely where untested code hides.
Recall from the previous topic that this is exactly the
pattern that leaves off-by-one and error-handling defects
alive.
Β· 2.81 defects/KLOC found in system test is a plausible
figure; published industry ranges are roughly 1β25 per
KLOC delivered depending on rigour, with high-maturity
organisations well under 1. But a LOW density can mean
either good code OR weak testing, and this metric alone
cannot tell you which β always read it beside coverage.
Β· 33 open defects and 17 blocked cases interact: fixing the
blockers may unblock cases that then find more defects.
The defect count has not stabilised.
IS IT READY TO RELEASE? On these numbers, no β and the
argument is not the pass rate but that (a) 14% of cases have
never been run, (b) branch coverage is 61% so the error paths
are largely unexercised, and (c) the defect discovery curve
has not flattened.
DEFECT REMOVAL EFFICIENCY, WORKED ACROSS PHASES:
found in review 42
found in unit test 67
found in integration 38
found in system test 91
βββββββββββββββββββββββββββββ
total pre-delivery E = 238
found by customers
in the first 6 months D = 19
DRE = 238 / (238 + 19) = 238/257 = 92.6%
INTERPRETATION: 7.4% of defects reached the customer. World
class is often quoted above 95%, and above 99% for
safety-critical work. The phase breakdown also tells you where
to invest: 42 found in review is a good return on a cheap
activity, and 91 in system test is expensive β those are
defects that got all the way through unit and integration
testing before being caught.
PHASE CONTAINMENT EFFECTIVENESS, per phase:
PCE = defects found in the phase they were INTRODUCED /
total defects introduced in that phase
A low PCE for design means design defects are escaping to be
caught in testing β at the 5Γ-to-50Γ cost multiplier from
the design topic.
The defect discovery curve, and how metrics get gamed
THE DEFECT DISCOVERY (RELIABILITY GROWTH) CURVE β cumulative
defects found, plotted against testing effort or time.
cumulative
defects β βββββββββ plateau: the
β βββββ curve FLATTENS
β ββββββ
β ββββββ
β βββββ
β βββ
ββββββββββββββββββββββββββββββ
testing time β
HOW TO READ IT β this is the practical release-readiness
judgement:
STILL RISING STEEPLY keep testing. There are plenty more
defects; stopping now ships them.
FLATTENING you are finding fewer per unit effort.
Either the code is getting clean, OR
your tests have stopped exploring new
territory β CHECK COVERAGE to tell
which.
FLAT WITH HIGH genuinely approaching readiness
COVERAGE
THE AMBIGUITY IS THE CRUX: a flat curve means either "few
defects remain" or "we have stopped looking in new places".
Coverage is what disambiguates, which is why the two families
of metric must always be read together.
DEFECT CLUSTERING (the Pareto observation): defects are not
uniformly distributed. Commonly ~80% of defects are found in
~20% of modules. THE ACTIONABLE CONSEQUENCE: a module with a
high defect count is not "nearly fixed" β it is the most
likely place for the NEXT defect too, and deserves more
testing, not less. Complexity metrics (V(G) from the heuristics
topic) predict these modules in advance.
THE PESTICIDE PARADOX: if the same tests are repeated, they
stop finding new defects β the code becomes immune to that
test set. Test suites must be reviewed and extended, not just
re-run.
HOW EACH METRIC IS GAMED β know these, because being able to
criticise a metric is what examiners reward:
COVERAGE
Gamed by writing tests with no assertions, or tests that
call everything and check nothing. 100% coverage with zero
assertions is achievable and worthless.
β measure MUTATION SCORE alongside, or review test quality
DEFECT COUNT
Gamed in both directions. Rewarding testers for defects
found produces many trivial reports; penalising developers
for defects introduced produces defects reclassified as
"requirements changes" and defects fixed without being
logged.
β never attach individual incentives to defect counts
PASS RATE
Gamed by deleting or disabling failing tests, or by writing
easy tests. A rising pass rate with a falling defect
discovery rate can mean the suite got weaker.
TEST CASE COUNT
Gamed by splitting one test into five. Counting tests
measures typing, not coverage of risk.
VELOCITY OF TEST EXECUTION
Gamed by running the fast, shallow tests first.
THE GENERAL PRINCIPLE: use metrics to ASK QUESTIONS, never as
targets attached to individuals. A metric's value is in the
anomaly it reveals β "why did branch coverage fall this
sprint?" β not in the number itself. This is Goodhart's law
applied to software, and it is the most important
professional judgement in this topic.
WHEN TO STOP TESTING β the honest answer combines several
signals, no one of which suffices:
Β· all planned test cases executed, with an acceptable pass
rate
Β· coverage targets met, including BRANCH coverage
Β· the defect discovery curve has flattened while coverage is
still growing
Β· no open defects above an agreed severity
Β· reliability measured against the requirement (MTBF, POFOD)
Β· the remaining risk is accepted explicitly by the customer
Testing is never "finished"; it is STOPPED, as a documented
risk decision. Saying that plainly is more professional than
pretending completeness.
The 78% statement / 61% branch split in the worked report is the pattern to recognise on sight. A large gap between the two means most decisions have been executed one way only β the error-handling paths are unexercised, and those are exactly the paths that run when something goes wrong in production.
π Go further: the DORA research programme (now the annual Accelerate State of DevOps report) identified four metrics that predict organisational software delivery performance, and they are notably not test metrics: deployment frequency, lead time for changes, change failure rate and time to restore service. The insight is that quality is better measured by outcomes at the delivery boundary than by activity inside the process β change failure rate is a truer statement about testing than any coverage number, because it counts what actually reached users. Search "DORA four key metrics change failure rate".
π‘ Exam angle: list the coverage, defect and effort metric families with examples. The two formulas most likely to be examined are defect density (defects per KLOC) and defect removal efficiency DRE = E/(E+D) β practise computing both from a table of phase data. Define the reliability metrics POFOD, ROCOF, MTTF and availability and say which suits which kind of system. Draw and interpret the defect discovery curve, explaining that a flattening curve is ambiguous without coverage data. Know defect clustering (the 80/20 observation) and the pesticide paradox, and be ready to discuss when to stop testing.
Syllabus points
Testing metrics
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Related topics in Testing, Cost Estimation, Quality & Configuration Management