What does test coverage measure?
Options
- How many tests exist in the project in total
- The share of lines or branches run by the tests (Correct option)
- How fast the tests of the suite finally run
- How many bugs exist in the code of the project
Answer
The percentage of code lines (or branches) executed while the tests run
Why
A coverage tool (e.g. pytest --cov) watches which lines run during the tests and reports a percentage, plus which lines were never executed.
Those uncovered lines are code no test checks at all, good places to add tests.
High coverage does not guarantee good tests: it doesn't check that assertions are meaningful.
Remember
Coverage = % of code executed by tests.