Measuring Prioritized Suite Effectiveness
Use APFD and related metrics to evaluate prioritized test suites — Chowdhury Chapter 10 | Elbaum et al. (2002)
Learning Objectives
- Define APFD and explain what it measures about a prioritized test suite.
- Derive and apply the APFD formula to calculate effectiveness for a given ordering.
- Interpret APFD values: understand the 0.5 random baseline, ideal value of 1.0, and typical ranges.
- Explain the APFDc (cost-aware) extension and when it is preferred over basic APFD.
- Define and calculate Time-to-First-Failure (TTFF) and Rate of Fault Detection (RFD).
- Apply the metric suite to benchmark two or more prioritization orderings.
Why Measure Prioritized Suite Effectiveness?
Prioritization is an investment: it requires calculation time, tooling, and ongoing recalculation. Without measurement, there is no evidence that the chosen ordering is better than random. Metrics are needed to:
Confirm that the chosen technique (general, version-specific, combined) actually detects faults earlier than an unprioritized or randomly ordered suite.
Objectively decide whether additional-coverage greedy outperforms FER-only ordering for this specific product and history.
Monitor whether APFD is improving or degrading as the suite evolves. A falling APFD indicates the prioritization model needs updating.
Provide a single number that answers: "How good is our test ordering?" Easier to communicate than raw pass/fail counts.
APFD: Average Percentage of Faults Detected
APFD (Elbaum et al., 2002)
What it measures: The speed at which a prioritized test suite detects faults, expressed as the area under the fault-detection curve (FDC). An APFD of 1.0 means all faults are detected immediately (ideal). An APFD of 0.5 means faults are detected at the same rate as a random ordering (the baseline). An APFD below 0.5 means the ordering is worse than random.
Intuition: Imagine running the test suite in order. Plot the percentage of total faults detected (y-axis) vs. the percentage of tests run (x-axis). APFD is the area under this curve divided by the total possible area (1.0).
APFD = 1 − (TF1 + TF2 + … + TFm) / (n × m) + 1 / (2n)
- n = total number of test cases in the suite
- m = total number of faults seeded/present in the version under test
- TFi = the position (1-indexed) in the ordered suite of the first test case that detects fault fi
- ∑TFi = sum of the first-detection positions for all m faults
- Ideal ordering: Every fault is detected by the first test case (TFi = 1 for all i). APFD = 1 − m/(n×m) + 1/(2n) = 1 − 1/n + 1/(2n) ≈ 1.0 for large n.
- Worst ordering: Every fault is detected by the last test case (TFi = n for all i). APFD = 1 − n×m/(n×m) + 1/(2n) = 1/(2n) ≈ 0.0 for large n.
- Random ordering: Expected TFi ≈ n/2. APFD ≈ 0.5. This is the no-skill baseline.
APFD Worked Example
Suite: 5 test cases (n=5). Faults: 3 faults (m=3): F1, F2, F3.
Each test case detects the following faults:
| Position | Test Case | Detects F1? | Detects F2? | Detects F3? |
|---|---|---|---|---|
| 1 | TC-A | Yes | No | No |
| 2 | TC-B | No | No | Yes |
| 3 | TC-C | No | No | No |
| 4 | TC-D | No | Yes | No |
| 5 | TC-E | No | No | No |
First-detection positions: TFF1 = 1 (detected at position 1); TFF2 = 4; TFF3 = 2.
APFD = 1 − (1 + 4 + 2) / (5 × 3) + 1 / (2 × 5)
= 1 − 7/15 + 1/10 = 1 − 0.4667 + 0.1000 = 0.633
APFD = 0.633 means this ordering detects faults 26.6% faster than a random ordering (0.5 baseline). All three faults are detected; the ordering accelerates early detection of F1 and F3.
| Position | Test Case | F1 | F2 | F3 |
|---|---|---|---|---|
| 1 | TC-D | No | Yes | No |
| 2 | TC-C | No | No | No |
| 3 | TC-E | No | No | No |
| 4 | TC-A | Yes | No | No |
| 5 | TC-B | No | No | Yes |
TFF1 = 4; TFF2 = 1; TFF3 = 5.
APFD = 1 − (4+1+5)/(5×3) + 1/(2×5) = 1 − 10/15 + 0.1 = 1 − 0.667 + 0.1 = 0.433
Conclusion: Ordering 1 (APFD=0.633) is significantly better than Ordering 2 (APFD=0.433). Ordering 2 is actually slightly worse than random (0.5). The metric provides an objective basis for choosing between orderings.
Interpreting APFD Values
| APFD Range | Interpretation | Action |
|---|---|---|
| < 0.50 | Ordering is worse than random. High-priority faults are detected late. | Investigate immediately: priority scores may be inverted or stale |
| 0.50 – 0.60 | Slight improvement over random. Prioritization provides minimal benefit. | Review priority scoring model; consider if weights need adjustment |
| 0.60 – 0.70 | Moderate improvement. Prioritization is working but not optimally. | Acceptable; monitor trend over time |
| 0.70 – 0.85 | Good prioritization. Early fault detection is substantially better than random. | Good state; maintain and recalibrate periodically |
| > 0.85 | Excellent prioritization. Near-ideal fault detection speed. | Validate that measurements are correct; exceptional results may indicate overfitting to past fault patterns |
- Treats all faults equally: A critical payment fault and a minor UI spacing fault contribute equally to APFD. Cost-weighted APFD (APFDc) addresses this.
- Requires known fault locations: Computing APFD requires knowing which test cases detect which faults. In practice, this requires fault seeding, mutation testing, or retrospective analysis of historical failures.
- Does not account for test execution cost: A suite where all faults are detected early but each test takes 20 minutes may have high APFD but poor practical performance. APFDc incorporates execution cost.
- Sensitive to suite size: For very small suites (n < 10), the 1/(2n) correction term dominates and APFD values are less meaningful.
APFDc: Cost-Aware Extension
APFDc (Elbaum et al., 2002)
Motivation: Basic APFD assumes each test case takes the same amount of time to execute. In reality, execution times vary dramatically. A case that detects a fault at position 3 but takes 30 minutes should be valued differently from one at position 3 that takes 1 minute.
- cost(tj) = execution time of test case tj
- cost_detectedi = cumulative execution time up to and including the test that first detects fault fi
- total_cost = total execution time of the entire suite
- m = total number of faults
5 cases, 2 faults. Execution times: TC-A=2min, TC-B=10min, TC-C=1min, TC-D=5min, TC-E=3min. Total = 21 min.
Ordering: TC-A, TC-B, TC-C, TC-D, TC-E. F1 first detected by TC-A; F2 first detected by TC-D.
- cost_detectedF1 = 2 (TC-A). cost(TFF1) = 2. Contribution = 2 − 2/2 = 1.
- cost_detectedF2 = 2+10+1+5 = 18 (TC-D). cost(TFF2) = 5. Contribution = 18 − 5/2 = 15.5.
APFDc = (1 + 15.5) / (21 × 2) = 16.5 / 42 = 0.393. The high cost of TC-B (10 min, detects no faults) penalizes this ordering. If TC-B were moved to the end (after TC-D), APFDc would improve significantly.
Time-to-First-Failure (TTFF)
TTFF
Definition: The wall-clock time elapsed from the start of the test run until the first test failure is observed (assuming at least one fault is present in the version under test).
Formula: TTFF = ∑j=1pos(first_failure) exec_time(tj)
Where pos(first_failure) is the position in the ordered suite of the first test that fails.
Why it matters: TTFF directly measures how quickly a developer can begin investigating a defect. In CI pipelines, TTFF determines how quickly the pipeline can be aborted and the developer notified. A lower TTFF means faster developer feedback.
| Metric | Measures | Best For |
|---|---|---|
| APFD | Overall fault detection speed across all faults | Comparing two orderings holistically; research benchmarking |
| TTFF | How quickly the first fault is detected | CI pipeline abort-early logic; developer notification latency |
A suite can have high APFD (good average detection speed) but poor TTFF (first fault detected late) if all faults happen to be concentrated in later tests. Both metrics together give a more complete picture.
Rate of Fault Detection (RFD)
RFD Curve
Definition: The Rate of Fault Detection (RFD) is the slope of the fault-detection curve at each point in the test run. It describes how the rate of fault detection changes as tests execute — not just the cumulative total.
RFDk = (Faults detected by tests 1–k) − (Faults detected by tests 1–(k-1))
A good prioritization strategy produces an RFD curve that is front-loaded: high detection rate early in the run, tapering off as the high-priority tests exhaust the available faults.
| Curve Shape | Interpretation |
|---|---|
| Steeply front-loaded (high early RFD, rapid decline) | Excellent prioritization: high-value tests run first; all faults detected early |
| Uniform / flat | Ordering is essentially random: no prioritization benefit |
| Back-loaded (low early RFD, spike at end) | Inverted priority: low-value tests run first; equivalent to reverse ordering |
| Bimodal (spike at start, flat middle, spike at end) | Two clusters of fault-detecting tests; version-specific P1 cases and general P1 cases are separated by low-value tests in the middle |
Metric Comparison Summary
| Metric | Formula Complexity | Data Required | Best Insight | Key Limitation |
|---|---|---|---|---|
| APFD | Low | Fault-detection positions | Overall ordering quality | Ignores execution cost; treats all faults equally |
| APFDc | Medium | Fault-detection positions + exec times + fault severity | Cost-adjusted ordering quality | Requires accurate execution time data |
| TTFF | Very Low | First failure time | CI fast-feedback; developer wait time | Only measures first fault; ignores remaining faults |
| RFD | Low | Per-test fault detection count | Shape of detection curve; identifies ordering anomalies | Qualitative; not a single summary number |
- CI pipeline monitoring: TTFF (primary) + APFD (trend tracking).
- Comparing prioritization algorithms: APFD (primary) + APFDc if execution times vary significantly.
- Diagnosing a poor-performing suite: RFD curve (to identify where in the run faults cluster).
- Safety-critical release gates: APFDc weighted by fault severity (high-severity faults detected early are worth more).
Benchmarking Two Prioritization Orderings
The standard benchmarking process for comparing two orderings A and B:
Module 5 Capstone: The Complete Suite Management Lifecycle
Module 5 has built a complete test suite management lifecycle. This capstone ties all sessions together:
| Session | Activity | Output |
|---|---|---|
| 5.1 Design Foundations | Apply EP, BVA, decision tables, white-box heuristics | Well-formed, non-redundant initial test suite |
| 5.2 Why Suites Grow | Diagnose growth drivers; classify cases | Redundancy classification: value-adding / low-value / redundant |
| 5.3 Minimization | Apply greedy/ILP; safe archive process | Minimized suite T′ with full coverage |
| 5.4 Benefits | Quantify ROI; present to stakeholders | ROI model; execution-time and maintenance savings |
| 5.5 Prioritization Goals | Define goal mix; build priority score model | Weighted priority scores for each case |
| 5.6 Prioritization Types | Apply general + version-specific algorithms | Ordered suite: version-specific P1 + general P2–P4 |
| 5.7 Measurement (this session) | Calculate APFD, APFDc, TTFF; compare orderings | Validated effectiveness metrics; evidence for ordering choice |
The lifecycle repeats. Measurement outcomes inform the next design and prioritization cycle. A well-governed suite improves continuously rather than degrading over time.
Common Mistakes
APFD is only meaningful when calculated regularly (per sprint or release). A single historical APFD tells you how good the ordering was; regular measurement tells you whether it is improving or degrading.
APFD measures fault detection speed, not coverage. A suite with high APFD and 50% branch coverage is good at detecting known faults early but may miss faults in uncovered branches entirely. APFD and coverage are orthogonal.
APFD is sensitive to suite size (the 1/(2n) term). Comparing APFD across suites of significantly different sizes (e.g., before and after minimization) requires careful interpretation. APFDc is more robust for cross-suite comparison.
Basic APFD weights all faults equally. For safety-critical systems, a weighted APFD where high-severity faults contribute more to the score is essential. Using unweighted APFD may optimise for early detection of minor faults while delaying critical ones.
Class Activity
| Position | Ordering A | F1 | F2 | F3 | F4 | Exec (min) |
|---|---|---|---|---|---|---|
| 1 | TC-H03 | Yes | No | No | No | 3 |
| 2 | TC-H01 | No | Yes | No | No | 8 |
| 3 | TC-H05 | No | No | No | No | 2 |
| 4 | TC-H02 | No | No | Yes | No | 4 |
| 5 | TC-H04 | No | No | No | Yes | 6 |
| 6 | TC-H06 | No | No | No | No | 5 |
| Position | Ordering B | F1 | F2 | F3 | F4 | Exec (min) |
|---|---|---|---|---|---|---|
| 1 | TC-H01 | No | Yes | No | No | 8 |
| 2 | TC-H06 | No | No | No | No | 5 |
| 3 | TC-H03 | Yes | No | No | No | 3 |
| 4 | TC-H04 | No | No | No | Yes | 6 |
| 5 | TC-H05 | No | No | No | No | 2 |
| 6 | TC-H02 | No | No | Yes | No | 4 |
- Calculate APFD for both Ordering A and Ordering B. Show all steps: identify TFi for each fault, compute ∑TFi, apply the formula.
- Calculate TTFF for both orderings (time in minutes to first failure).
- Calculate APFDc for Ordering A. (Total suite execution time = 3+8+2+4+6+5 = 28 min.)
- Which ordering is better? Justify your answer using all three metrics.
- F2 (payment failure) is classified as a critical severity fault. If you were to modify APFD to give F2 twice the weight of other faults (weighted APFD), would this change which ordering is preferred? Recalculate.
Exit Ticket
- A test suite has n=8 cases and m=2 faults. Ordering X has TFF1=1, TFF2=2. Ordering Y has TFF1=7, TFF2=8. Calculate APFD for both. Which is better and by how much?
- A suite achieves APFD = 0.48. What does this tell you about the ordering? What corrective action would you take?
- Why does APFDc penalize orderings that place long-running tests that detect no faults early in the queue?
- What is the relationship between APFD measurement and the prioritization recalibration cycle? How often should APFD be measured, and what threshold would trigger a recalibration?
Summary & Module 5 Close
APFD is the primary metric for measuring the effectiveness of a prioritized test suite. It quantifies early fault detection as a value between 0 and 1, with 0.5 as the random baseline. APFDc extends this to account for varying execution costs. TTFF measures how quickly the CI pipeline can give actionable feedback. The RFD curve reveals the shape of fault detection over time. Together, these metrics provide the evidence needed to validate prioritization investment and continuously improve the ordering.
- APFD = 1 − ∑TFi/(n×m) + 1/(2n). Range: ~0 (worst) to ~1 (best). Baseline: 0.5 (random).
- APFD > 0.70 is a good target for most commercial software prioritization.
- APFDc accounts for execution cost; prefer it when test execution times vary significantly.
- TTFF is the operationally critical metric for CI/CD abort-early decisions.
- RFD curves diagnose ordering shape: front-loaded is good; flat or back-loaded needs correction.
- Measure APFD regularly; a declining trend signals that priority scores need recalibration.
Bring together all Module 5 sessions for your mini-project suite:
- (5.1) Verify your suite passes the 8-point quality checklist. Report any cases revised.
- (5.2) Complete the growth diagnosis: report redundancy percentage by type.
- (5.3–5.4) Apply greedy minimization; report T′ size, coverage verification result, and 2-year ROI model.
- (5.5–5.6) Produce the combined prioritization ordering (version-specific + general) for T′. Include the priority score table and weight rationale.
- (5.7) Calculate APFD for your prioritized ordering using fault data from your project's defect tracker (historical failures as proxy faults). Compare with a random ordering APFD to quantify the improvement.
- Report: Submit a 1–2 page "Test Suite Management Report" summarising: initial suite size, minimized suite size, APFD before and after prioritization, execution time saving, and one governance recommendation to prevent re-bloat.