Code Quality

What is Code Coverage?

Code coverage measures what percentage of source code is executed during automated testing — a proxy for test suite completeness, with line, branch, and path coverage as the main variants.

By the Hyrax team·5 min read·May 1, 2026
TL;DR
  1. 1.Definition
  2. 2.Types of Code Coverage
  3. 3.What Coverage Tells You — and What It Does Not
  4. 4.Coverage in CI/CD
  5. 5.Code Coverage and Autonomous Code Governance

Definition

Code coverage is a metric that measures the percentage of source code that is executed when a test suite runs. It indicates which lines, branches, functions, or paths in the code are exercised by tests and which are not. High code coverage reduces the probability of uncaught bugs by ensuring more of the code is tested; low coverage leaves large portions of the codebase untested and potentially broken.

Coverage is measured by instrumenting the code (adding counters to track which code is executed) and running the test suite. After the run, the coverage report shows exactly which lines were hit and which were missed.

Types of Code Coverage

Line coverage (statement coverage)

The percentage of individual lines (or statements) that were executed. The simplest and most common metric. A line is covered if any test causes it to execute. Line coverage at 80% means 80% of lines were executed by at least one test.

Branch coverage

The percentage of branches taken. For an if/else statement, line coverage is achieved when either the if or the else executes; branch coverage requires both to be tested. Branch coverage is stricter than line coverage and catches more bugs.

Function/method coverage

The percentage of functions or methods that were called during testing. Useful for identifying dead code (functions that are never called in tests are often never called at all).

Path coverage

The percentage of all possible execution paths that were tested. The most thorough coverage metric, but the number of possible paths grows exponentially with branching — making 100% path coverage impractical for all but the simplest functions.

Coverage typeWhat it measuresStrictnessPractical threshold
Line/statementLines executedLow80% (industry standard)
BranchBoth sides of every branchMedium70–80%
FunctionFunctions calledLow90%+
PathAll execution pathsVery highHigh paths count makes 100% impractical

What Coverage Tells You — and What It Does Not

Coverage is a necessary but insufficient measure of test quality:

  • High coverage means most code is executed during tests — but tests can execute code without asserting correct behavior
  • A test that calls a function without checking its return value achieves coverage without verifying correctness
  • Coverage misses incorrect logic that happens to produce a correct result for the tested inputs

Coverage tells you what code is not tested (important). It does not tell you whether the tests that exist are good (also important). Mutation testing addresses the second gap.

Coverage in CI/CD

Coverage gates in CI/CD enforce minimum coverage thresholds:

  • Fail the build if overall coverage drops below a configured threshold (e.g., 80%)
  • Fail the build if a pull request decreases coverage for the changed files
  • Report coverage trends to catch gradual erosion before it becomes a problem

Code Coverage and Autonomous Code Governance

Code coverage feeds into autonomous code governance in two ways. First, as a quality metric: governance systems track coverage trends and detect when merges reduce coverage, potentially generating tests to restore it. Second, as a verification tool: when Hydra generates a fix for a vulnerability, it runs the test suite to confirm that existing coverage is maintained and that the specific behavior targeted by the fix is tested.

Hydra also generates baseline tests before applying fixes — ensuring that the fix can be verified by dynamic analysis, not just static inspection.

Frequently Asked Questions

What is a good code coverage percentage?

80% line coverage is a widely cited industry target. Many organizations target 80% for line coverage and 70% for branch coverage as minimum thresholds. Security-critical code often warrants higher targets (90%+). Above 90%, the marginal cost of coverage (writing tests for edge cases) often exceeds the marginal benefit.

Can 100% code coverage guarantee bug-free code?

No. 100% line coverage means every line executed — it says nothing about whether the tests check correct behavior. A test suite that calls every function without asserting anything can achieve 100% line coverage while catching zero bugs. Coverage is a floor, not a ceiling.

What is mutation testing?

Mutation testing evaluates test suite quality by making small changes (mutations) to the source code — swapping a + for a -, flipping a boolean condition — and checking whether the tests catch the change. A mutation that is "killed" (causes tests to fail) indicates a good test. A "surviving" mutation indicates a gap in test quality. Mutation testing answers the question coverage does not: are the tests actually checking correct behavior?

Stop flagging. Start fixing.

Hyrax reviews your pull requests, remediates issues autonomously, and closes the ticket.

Join the waitlist