Basics

What is code coverage — and why 100% doesn't mean “tested”

Illustration: a wall of bulbs fully lit while the magnifying glass lies untouched on the floor

Look at this annoying little fact: you can write a test with no assertion in it at all — just call the function and compare nothing. And code coverage will happily report 100%. The report is green and nothing was verified. Let's unpack what coverage actually measures and how to use it without fooling yourself.

What code coverage means in plain words

Code coverage is the share of lines in your program that ran while the tests executed.

It works like this: the tool runs your tests and ticks off every line execution reached. At the end it divides ticked lines by all lines. You got 68% — two thirds of the code ran at least once during the test run, and a third never executed at all.

Picture a wall of light bulbs where each bulb is a line of code. You run the tests and bulbs light up one by one. Coverage is how many are lit. And here's the whole point: a lit bulb only tells you execution passed through. Not that anyone looked at the result.

The core catch: coverage measures execution, not verification

From that comes a rule that saves months of self-deception:

Coverage is a metric of execution, not of correctness.

You called the discount function, compared the result to nothing — the lines ran, coverage went up, and whether the function works you still have no idea. A test with no assertion isn't a test, it's a walk through the code.

This is especially easy to hit when AI writes the tests. Ask for "raise the coverage" and you'll get exactly that: calls to every function, minimal meaningful checks. So when you work with AI on tests, read the assertions first, not the test count: what is compared, and against which expected value. This is also why AI-written code has bugs while tests stay green.

Lines and branches are two different numbers

A report usually shows at least two figures, and confusing them is expensive.

  • Line coverage — how many lines ran. The most popular and most misleading number.
  • Branch coverage — how many forks were taken in both directions. Every condition has two outcomes; the line counts as covered even if you only exercised one of them.

Example: a function with "if the user isn't found, return an error". A test with an existing user runs the condition line, and line coverage is delighted. The "not found" branch never executed — precisely the one that breaks in production. Branch coverage catches that; line coverage doesn't.

Takeaway: look at branches. If your tool counts them, turn it on.

How to use coverage without lying to yourself

Three practical habits:

  1. Read the report, not the percentage. Almost every tool renders your file with highlighting: green ran, red didn't. The value is in the red. Look at it and ask: "is this spot dangerous?"
  2. Don't make the number a target. The moment people report on a figure, they start inflating it with empty tests — a well-known law. Coverage works well as an indicator and badly as a KPI.
  3. Don't chase one number everywhere. Payment logic and permission checks deserve near-complete coverage. The markup of your About page does not. 100% across a whole project usually means a pile of pointless tests that later block every change and turn into technical debt.

There's a more honest tool too — mutation testing. It deliberately breaks your code (flips a plus to a minus, inverts a condition) and checks whether the tests fail. If they don't, the tests verify nothing, whatever the coverage says. It's slow, but one run over an important module is very sobering.

What percentage of coverage is normal?

There's no universal number, and anyone who names one without context is bluffing. A working guide: critical business logic at 80%+ on branches, everything else as it comes. Far more important is that coverage doesn't drop from change to change — an easy check to wire into CI/CD.

Do I need coverage if AI writes the code?

Even more so. You read someone else's code with your eyes and easily miss an unhandled branch — a coverage report flags it mechanically. Just don't ask AI to "make it 100%": ask for a test on the specific branch that stayed red.

How is coverage different from the number of tests?

The number of tests tells you nothing: a hundred tests can crowd into one function. Coverage answers a different question — which parts of the code were never touched. Different questions, and neither answers a third one: does the program actually work correctly.

Become an AI architect — don’t just read about AI

The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.

About the Academy
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →