Web apps & software

What is code coverage?

Code coverage is a measurement of how much of a program's source code is executed while its automated tests run, usually shown as a percentage of lines, branches or functions.

What the number tells you

If a report shows 40 percent coverage, 60 percent of the code is never touched by a test, which is a map of where bugs can hide unnoticed. Tools such as JaCoCo, Istanbul/nyc, coverage.py and Xdebug produce the report and highlight untested lines.

What it does not tell you

A line can run without anything checking its result. A test that calls a function and asserts nothing raises coverage while proving nothing. High coverage with weak assertions gives false comfort.

Sensible use

  • Treat it as a flashlight for finding untested risky areas, not a score to maximize.
  • Look at branch coverage, which shows untested if/else paths.
  • Set a floor, perhaps on new code in a pull request, instead of a company-wide target that invites gaming.
  • Pair it with reviews and mutation testing, which checks whether tests notice deliberate bugs.

Payment and pricing logic deserve higher coverage than a static about page.

Questions, answered

Many teams settle between 70 and 85 percent overall, with higher on critical logic. The right level depends on risk.

No. It only means every line ran at least once.

By the Stegnor team · Updated