Test coverage

From NeoLabHQ/context-engineering-kit · View interactive version

Test coverage is an AI agent skill from the GitHub repository NeoLabHQ/context-engineering-kit. Use after writing tests to assess coverage quality across structural, mutation, requirements, and API/integration dimensions; organized knowledge for choosing and interpreting coverage analyses.

How to use this skill

Skill file

Test Coverage Analysis

A reference manual for choosing, applying, and interpreting test-coverage analyses on an existing test suite.

This skill is a knowledge reference, not a procedure. It does not tell you when to write tests or which test types to design — that is the job of design-testing-strategy. It tells you, once tests exist, which mechanical signal best measures what those tests do (and do not) exercise, and how to read that signal honestly.

What Coverage Analysis Is

Test coverage analysis is the post-hoc measurement of how thoroughly a test suite exercises a software artifact along one or more axes. It answers the question "what did my tests actually touch?" — for some specific definition of "touch."

The word "coverage" is overloaded. It can mean any of:

Category correction: coverage is not a test type

Mutation testing, MC/DC, branch coverage, RTM linkage, contract coverage, and schema coverage are measurements about an existing test suite. They are not test types in the way unit, integration, e2e, contract, or smoke tests are.

If a "test strategy" places mutation testing alongside unit / integration / e2e, that strategy has confused what to test with how to measure the tests. The two questions are orthogonal.

The asymmetry principle

Low coverage is strong evidence of weak testing. High coverage is weak evidence of strong testing.

Coverage is necessary-but-not-sufficient. A test can execute a line without asserting anything meaningful; 100% line coverage is routinely achievable with zero assertions (thinkinglabs.io, codeintelligently.com). Use coverage as a tripwire, not a trophy. Once a coverage percentage becomes a target, it ceases to be a good metric (Goodhart's law applied to testing; see Optivem Journal).

What coverage analysis is NOT


Per-Type Structure

Every coverage type in this skill is documented in the same six sub-fields, in this order:

  1. Definition — what it measures.
  2. What it does NOT measure — its limits / blind spots.
  3. Typical tools — per ecosystem.
  4. When to use vs skip — applicability heuristics.
  5. Targets / thresholds & pitfalls — defensible numeric ranges (always with the risk caveat) and common gaming patterns.
  6. Cost-benefit ROI — order-of-magnitude cost vs the signal you actually buy.

Scan any section by these headings.


Structural / Code Coverage

Measured by instrumenting the compiled or interpreted program and recording which structural elements (lines, statements, branches, conditions, paths) the test suite executes.

Line / Statement Coverage

| Ecosystem | Tool |

|-----------|------|

| JS/TS | Istanbul / nyc (built into Jest, Vitest, Karma); --coverage flag |

| Python | Coverage.py + pytest-cov; supports branch mode |

| JVM | JaCoCo — bytecode instrumentation, industry standard |

| C/C++ | gcov / lcov / gcovr, llvm-cov |

| Go | go test -cover, go tool cover (build-cover added integration-test mode in Go 1.20) |

| .NET | Coverlet (open-source default), JetBrains dotCover, AltCover. OpenCover is in maintenance mode — prefer Coverlet / dotCover / AltCover (NDepend guide) |

| Ruby | SimpleCov |

| Swift / Obj-C | Xcode built-in (llvm-cov backend) |

| Rust | cargo-llvm-cov, cargo-tarpaulin |

| Report formats | Cobertura XML, LCOV, Clover; aggregators: Codecov, Coveralls, SonarQube |

Branch / Decision Coverage

Condition Coverage

| Ecosystem | Tool |

|-----------|------|

| JVM | JaCoCo (condition counters in branch reports) |

| C / C++ | gcov/gcovr (--branch-counts), Qt Coco |

| .NET | Coverlet (condition coverage via Cobertura output) |

MC/DC — Modified Condition/Decision Coverage

1. Every entry/exit point invoked at least once.

2. Every decision has taken every outcome at least once.

3. Every condition in a decision has taken every outcome at least once.

4. Each condition has been shown to independently affect the decision's outcome (holding the other conditions fixed).

For n conditions, MC/DC is achievable with n+1 to 2n tests via independence pairs — vastly cheaper than the 2^n of exhaustive multiple-condition coverage (LDRA).

Function / Method Coverage

| Ecosystem | Tool |

|-----------|------|

| JVM | JaCoCo (method counter) |

| .NET | Coverlet (methods column) |

| Python | coverage.py (report -m granularity), pytest-cov |

| JS/TS | Istanbul (functions metric in lcov / json-summary) |

Path Coverage

| Ecosystem | Tool |

|-----------|------|

| Safety-critical C/C++ | LDRA TBvision, VectorCAST (basis-path metrics) |

| Any / complexity proxy | lizard, radon, SonarQube (cyclomatic complexity as a bound, not a path metric) |


Mutation Testing as Coverage Analysis

Reminder: Mutation testing is a coverage analysis of an existing test suite. It is not a test type. It produces a score and a list of survived mutants; it does not produce new tests. You apply it to your unit / integration suite, not instead of it.

Definition

Mutation testing introduces small, syntactic modifications ("mutants") to the source and re-runs the existing test suite against each mutant. If at least one test fails for a given mutant, the mutant is killed (the suite detected the fault). If all tests pass, the mutant survived (the suite is blind to that change). It measures test-suite fault-detection power, not source-code reach (Stryker docs).

Typical mutation operators:

Mutant states ([Stryker docs](https://stryker-mutator.io/docs/mutation-testing-elements/mutant-states-and-metrics/))

| State | Meaning |

|-------|---------|

| Killed | At least one test failed on the mutant. Suite detected the fault. |

| Survived | All tests passed on the mutant. Suite is blind. |

| No coverage | No test executed the mutated code (orthogonal gap — code itself is untested). |

| Timeout | Tests hung; usually counted as a kill (the suite did observe abnormal behavior). |

| Compile error / runtime error | Mutant is syntactically/semantically invalid; usually filtered. |

| Ignored | Filtered by config (generated code, glue, etc.). |

Score: mutation_score = killed_mutants / (total_mutants - equivalent_mutants - errors). Some tools also report a "killed%" relative to covered mutants only.

What it does NOT measure

Typical tools

| Ecosystem | Tool |

|-----------|------|

| JS / TS | Stryker (StrykerJS) — TypeScript checker plugin filters compile-error mutants |

| .NET (C#) | Stryker .NET; documented in Microsoft Learn |

| Java / JVM | PIT (Pitest) — reference standard for JVM; Major Mutator for research |

| Python | mutmut, Cosmic Ray, MutPy |

| Go | go-mutesting, ooze |

| PHP | Infection |

| Ruby | mutant |

| Rust | cargo-mutants |

| C / C++ | Mull — LLVM-based |

| Scala | Stryker4s |

When to use vs skip

Apply when:

Skip when:

Targets / thresholds & pitfalls

Stryker defaults (config): high: 80, low: 60, break: null. Set break to fail the build below a floor. Apply with the risk caveat: 60–80% on a mature unit suite over pure-logic core is a reasonable starting point; never on glue code. Common pitfalls: chasing equivalents (asymptote), running on UI/config (noise), running on shallow suites (re-reports what coverage already shows).

Cost-benefit ROI

Relationship to structural coverage

Mutation testing subsumes and supplements structural coverage:


Requirements / Feature Coverage

Definition

Mapping between specification artifacts (requirements, user stories, acceptance criteria, regulatory clauses) and verifying tests:

requirements_coverage = requirements_with_>=1_passing_test / total_requirements

The foundational artifact is the Requirements Traceability Matrix (RTM) — a two-dimensional table correlating requirements to test cases (ISTQB Glossary). Enables:

What it does NOT measure

Typical tools

| Tool | Type | Notes |

|------|------|-------|

| Jira + Xray / Zephyr / Test Manager | ALM | Stories ↔ tests linked in tickets |

| Polarion, IBM DOORS / DOORS Next, Codebeamer | Regulated-domain ALM | Tier 1 for DO-178C / ISO 26262 |

| Spreadsheet + tags in test names | Lightweight | Works for small teams; deteriorates at scale |

| BDD scenario reports | BDD-aligned | Cucumber + Pickles report generator |

| @Tag("AC-123") style annotations | Code-level | JUnit / pytest tag-based linking to AC IDs |

In BDD ecosystems, Gherkin Scenario: blocks are the unit of acceptance coverage; each AC ideally maps to one or more scenarios (the Cardinal Rule of BDD: one scenario, one behavior — Automation Panda). Tools: Cucumber (multi-language), SpecFlow (note: the active community fork is Reqnroll), behave (Python), pytest-bdd, Robot Framework, Behat (PHP).

Foundational standards: ISTQB Foundation Level treats RTM as a foundational artifact for systematic test design. ISO/IEC/IEEE 29119 parts 1–5 require traceability at the test-plan, test-design, and test-execution levels (ISTQB-to-29119 mapping in rcolomo.com). Regulatory traceability is mandatory in DO-178C, ISO 26262 Part 6 work products, IEC 62304 verification record, and FDA 21 CFR Part 820.

When to use vs skip

Targets / thresholds & pitfalls

100% requirements coverage is a reasonable goal — every documented AC should have at least one test. The pitfalls are qualitative, not numerical:

Cost-benefit ROI


API / Integration Coverage

API coverage measures the integration surface — endpoints, methods, status codes, payload fields, and inter-service contracts — exercised by the test suite, independent of code coverage.

Endpoint Coverage

Contract Coverage (Consumer-Driven Contracts)

Schema Coverage (OpenAPI / JSON Schema / GraphQL)

Integration-Path Coverage


Additional Coverage Types

Data / Equivalence-Class Coverage

Pairwise / Combinatorial Coverage

Exception / Error-Path Coverage

State / Transition Coverage


Cross-Cutting Topics

Combining methods — what each one cannot show

Different coverage axes detect different bug classes. Combining them is multiplicative, not additive.

Worked example — input validator for a discount code. Consider if (code.length > 0 && code.startsWith("PROMO")). A single happy-path test with "PROMO10" produces:

| Axis added | What it newly catches | What still hides |

|------------|----------------------|------------------|

| Line only | Everything executes once — 100% line. | Both empty-string and non-PROMO rejection paths are untested; a refactor to >= 0 ships green. |

| + Branch | Forces a false-branch test, e.g. "". Now the empty-string case is exercised. | A weak assertion (expect(result).toBeDefined()) still kills no bugs; mutating > → >= leaves the suite green because no test asserts the specific rejection. |

| + Mutation | Killing the > → >= and startsWith → endsWith mutants forces tests with specific assertions on the rejection outcome. | A boundary value like code.length === MAX is still untested — that requires Boundary / data coverage. |

| + Data (BVA) | Adds the MAX, MAX+1, and null cases. | A second consumer that calls this validator with code = undefined is still uncaught — that requires Contract coverage. |

Each new axis closes a class of fault the previous axes structurally cannot see — branch alone can never detect weak assertions, mutation alone can never detect untested boundary values, and contract coverage alone can never detect logic bugs. That is the multiplicative effect. The table below lists each axis and the blind spots it has — read it as "to fill this blind spot, layer another axis."

| Axis | Blind to |

|------|----------|

| Statement / line | Untaken branches, missing assertions, wrong return values |

| Branch / decision | Compound-condition independence, loop iteration counts, assertion strength |

| MC/DC | Data-value boundaries (still need BVA), assertion strength |

| Path | Combinatorial explosion at runtime; impractical beyond toy functions |

| Mutation | Dead-code regions (no coverage); semantic correctness of assertions (a wrong-but-strict assertion still kills mutants) |

| RTM / requirements | Whether the requirement is complete; whether the test is correct |

| Endpoint / API | Field-level shape correctness; behavioral correctness |

| Contract | Negative space — provider features no consumer uses |

| Schema | Semantic correctness; field meaning |

| Pairwise | 3-way+ interactions; ordering effects |

| State-transition | Data carried across transitions; non-modeled behavior |

| Error-path | Whether the error was handled correctly |

A typical layered stack for non-regulated product code:

  1. Branch coverage — CI gate and regression tripwire.
  2. Requirements / AC linkage — every acceptance criterion has at least one test.
  3. Mutation testing — nightly on pure-logic core modules only.
  4. Pairwise — on multi-parameter config / feature surfaces.
  5. Contract / endpoint coverage — for public APIs.
  6. State-transition coverage — for workflows.

This stack costs marginal CI minutes and surfaces the majority of test-suite blind spots that matter in practice.

The weak-assertion pitfall

The single most common reason high coverage fails to reflect quality:

// 100% statement coverage. 0% useful.
it("computes discount", () => {
  discount(150);            // line executed
  // no assertion
});

Or, more subtly:

// 100% statement coverage. Verifies nothing semantic.
it("renders form", () => {
  expect(render(<Form />)).toMatchSnapshot();
});

Both tests execute every line they touch and produce green coverage reports. Both are detected by mutation testing: every operator mutation in discount survives because no assertion can fail; every change in <Form /> survives because the snapshot can be updated with --update-snapshot. Coverage alone cannot distinguish these from a strong suite. Mutation testing can.

Counter-measure: when a coverage report shows ≥80% with persistent bugs in production, run mutation analysis on the suspect modules before raising the coverage target.

Risk-based interpretation

Coverage targets should be proportional to risk (ISO/IEC/IEEE 29119). The same artifact at different criticalities should not have the same coverage gate. Use the table below as a starting point — adjust per artifact, not per team policy.

| Criticality | Reasonable structural target | Mutation? | RTM? | MC/DC? |

|-------------|------------------------------|-----------|------|--------|

| NONE (docs, throwaway) | — | No | No | No |

| LOW (internal tooling) | 60% line | No | Lightweight | No |

| MEDIUM (CRUD / standard product) | 70–80% branch | On core logic only | Per AC | No |

| MEDIUM-HIGH (user-facing critical path) | 80% branch | On core logic + key validators | Mandatory | No |

| HIGH (money, auth, security) | 90%+ branch | Required on pure-logic core | Mandatory + audit-grade | Where standard mandates |

| Regulated | Per standard | Recommended on pure-logic core | Mandatory + audit-grade | Required where standard mandates |

Delta thresholds ("must not drop more than X%") are generally safer than absolute floors — they protect against regression in testing discipline without rewarding gaming (Optivem). The exception is greenfield code, where there is no baseline to delta against.

Common gaming patterns to recognize

  1. Assertion-free tests — execute code without verifying behavior. Mutation testing reveals these.
  2. Snapshot-only tests inflating numbers — expect(component).toMatchSnapshot() covers every line but verifies nothing semantic; one careless --update-snapshot invalidates the suite. Counter: cap snapshot contribution, or require an accompanying behavior assertion.
  3. Coverage of dead code — code unreachable in production but exercised by tests via reflection / test-only entry points. Static analyzers (SonarQube, Coverity) flag dead code; CI should fail when dead code increases.
  4. Try/catch wrappers to suppress failures while still executing lines.
  5. One-line condensation to drop branch counts (a && b && doX() instead of if (a && b) doX();) — tooling-dependent gaming.
  6. Excluding files from coverage without a recorded reason. Counter: require a // coverage:ignore comment with a rationale that survives code review.
  7. Coverage on generated code inflating the denominator. Counter: exclude *.generated.* deterministically.
  8. Counting tests planned but not passing in the RTM.
  9. Tagging multiple ACs with one trivial test to make the RTM look green.
  10. Stale traces — old Playwright / OpenTelemetry traces masking current gaps.

Instrumentation caveats

Regulated-domain coverage standards

| Standard | Domain | Coverage requirement |

|----------|--------|----------------------|

| DO-178C §6.4.4.2, Table A-7 | Avionics | MC/DC required for DAL A; Decision coverage for DAL B; Statement coverage for DAL C; none for DAL D/E (LDRA structural coverage) |

| ISO 26262 Part 6 Table 9 | Automotive | MC/DC highly recommended for ASIL D; branch for ASIL B–C; statement minimum for ASIL A (Verifysoft) |

| IEC 62304 | Medical | Coverage scales with safety class A → B → C; auditors expect MC/DC for Class C high-risk modules; MISRA C/C++ coding standards customary alongside |

| MISRA C / MISRA C++ | Embedded (cross-industry) | Coding-rule conformance is the primary signal; coverage is complementary; MC/DC expected for safety-critical components |

| EN 50128 / EN 50657 | Rail | MC/DC required for SIL 4 |

| IEC 61508 | Functional-safety umbrella | MC/DC for SIL 4 |

In regulated domains, the coverage target is set by the standard, not negotiated against ROI. The choice is which standard applies, not what threshold to pick.


Decision Reference Tables

These are lookup tables, not steps. Read the row that matches your artifact and criticality; ignore the rest.

Coverage methods by criticality

| Criticality | Recommended coverage signals |

|-------------|------------------------------|

| NONE | None — explicit skip |

| LOW | Line coverage as tripwire; AC linkage if the work has ACs |

| MEDIUM | Branch coverage + AC linkage; endpoint coverage if API artifact |

| MEDIUM-HIGH | Branch coverage + AC linkage + endpoint / contract coverage; mutation on validators |

| HIGH | Branch coverage + mutation on pure logic + AC linkage + state-transition coverage for workflows + pairwise for config; MC/DC where standard mandates |

| Regulated (DO-178C / ISO 26262 / IEC 62304) | Whatever the standard prescribes — usually MC/DC + RTM + auditable evidence |

Coverage methods by artifact type

| Artifact | Most informative coverage axes |

|----------|--------------------------------|

| Pure utility function (parser, calculator, formatter) | Branch + BVA/EP + mutation |

| HTTP endpoint with DB / queue | Branch (unit) + endpoint + contract + status-code |

| UI component | Storybook story coverage + interaction coverage + visual regression baseline; logic helpers via branch + mutation |

| Workflow engine / state machine | State-transition (0-switch minimum, 1-switch on critical paths) + branch |

| Authorization / policy module | Branch + MC/DC if regulated, otherwise branch + mutation; decision-table coverage at design time |

| Multi-parameter config / feature flag | Pairwise (PICT / ACTS) + branch |

| Public API consumed by N clients | Contract (Pact) + endpoint + schema |

| Library / SDK | Branch + property-based; mutation on pure logic; published-API surface coverage |

| Generated code | Excluded from structural coverage; verify via integration only |

Ecosystem toolchain quick-reference

| Ecosystem | Structural | Mutation | API | Combinatorial | BDD |

|-----------|-----------|----------|-----|---------------|-----|

| JS / TS | Istanbul/nyc, Vitest, Jest | Stryker | Schemathesis, Pact JS, Dredd | PICT | Cucumber-JS, Vitest+Gherkin |

| Java / JVM | JaCoCo | PIT | Pact JVM, Spring Cloud Contract | jcunit / NIST ACTS | Cucumber-JVM |

| Python | Coverage.py + pytest-cov | mutmut, Cosmic Ray | Schemathesis, pact-python | NIST ACTS, allpairspy | behave, pytest-bdd |

| Go | go cover + gocover-cobertura | go-mutesting | Schemathesis, pact-go | (manual / NIST ACTS) | godog |

| .NET | Coverlet, dotCover, AltCover (OpenCover deprecated) | Stryker .NET | Pact .NET, Specmatic | PICT, NIST ACTS | Reqnroll (active fork of SpecFlow) |

| Ruby | SimpleCov | mutant | pact-ruby | (manual) | Cucumber, RSpec |

| C / C++ | gcov/lcov, llvm-cov | Mull | (vendor-specific) | NIST ACTS | (vendor-specific) |

| Rust | cargo-llvm-cov, tarpaulin | cargo-mutants | (limited) | proptest combinators | (limited) |

| PHP | Xdebug / PCOV | Infection | pact-php | (manual) | Behat |

UI / interaction coverage extras

For UI-heavy projects, these specialized coverage signals supplement (do not replace) structural and mutation analysis:

These do not measure logic correctness (use branch + mutation for that), cross-component flows (use e2e), accessibility (use axe-core / Pa11y), or real-device variations (use BrowserStack / Sauce / device farms).


Sources & Further Reading

Standards

Structural & MC/DC

Structural coverage tooling

Mutation testing

Requirements / BDD

API / contract

Combinatorial / state / UI

Industry commentary

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.