Skip to content
BENIBIX Learn

Test Coverage

Development🧪 Testing & QualityTest Practices

Also known as Code Coverage, Coverage Report, Line Coverage

How much of your code your tests really run, as a percent.

Think of it like

Think of it like a map of a house that shows which rooms you have checked.

Example

Jack's report says cart.py has 50% coverage. The discount function never runs in any test, so he writes one for it.

Why it matters

It points at code no test has ever touched, which is where untested bugs wait.

Definition

Test coverage is how much of your code runs when the tests run. It is shown as a percentage. A tool watches the tests and marks each line that was reached. A report then lists the lines no test touched. Many teams aim for around 80%. But coverage only says a line ran, not that a test checked its result.

Example code

console
$ pytest --cov=cart
Name      Stmts   Miss  Cover
cart.py       6      3    50%
Half the lines in cart.py never ran during the tests.

Common mistake

Chasing 100% coverage. Tests written just to raise the number often check nothing.

Key takeaways

  1. 1
    A percentage. Of lines the tests ran.
  2. 2
    Shows the gaps. Lines no test touched.
  3. 3
    Ran is not checked. A high number can mislead.