Skip to content
IT glossary
TestingUpdated December 3, 2026

Code coverage

Покрытие кода

Code coverage measures how much of a program runs while tests are running. It can count lines, functions, or branches, but it does not tell you whether the tests checked the results.

Also known as: coverage

What code coverage tells you

A passing test run tells you that none of its checks failed. A coverage report answers a different question: which parts of the implementation did the tests actually run? If a report shows 80% line coverage, the tests executed 80% of the executable lines included in the measurement. That number is not the percentage of requirements tested or bugs caught.

How coverage is measured

A coverage tool records execution while the tests run. It might add counters to the program or collect events from the runtime, then map the results back to source files. For each metric, it divides the number of items executed at least once by the total number of eligible items. Running the same line a hundred times counts no more than running it once.

  • Line coverage counts executable source lines reached during the run. Comments and blank lines do not count.
  • Function coverage counts functions that ran, even if the tests reached only part of their bodies.
  • Branch coverage counts control-flow alternatives taken. A simple if has a true and a false outcome even if there is no else. Tools can differ in how they count branches in more complex expressions.

Why 100% line coverage can miss behavior

def shipping_cost(subtotal):
    cost = 5
    if subtotal >= 50:
        cost = 0
    return cost

The test assert shipping_cost(75) == 0 runs every line in the function body. It never takes the false branch, which leaves the shipping cost at 5. Add assert shipping_cost(49) == 5 and both branches are covered. Yet both tests would still pass if someone accidentally changed >= to >. A test at exactly 50 catches that mistake. The report can point you to an unvisited branch, but it cannot choose the boundary values for you.

How teams use coverage reports

Coverage can come from unit, integration, or end-to-end tests, provided the tool measures the code those tests exercise. During code review, look at uncovered lines and branches in the change, especially those that handle errors or enforce business rules. A CI threshold can flag a drop, but a repository-wide average can hide a poorly tested module. Compare reports only after checking which files, tests, and metrics they include: excluding files can raise the percentage without improving the suite.

What to explain in an interview

Be ready to distinguish reaching code from verifying its behavior. A test that calls shipping_cost(75) without checking the return value still contributes to coverage, but it won't catch a wrong price. If asked what test to add next, name the input and expected result rather than just saying you would raise the percentage.