FresherTechnicalBackend testing
What does a 90 percent code coverage number tell you, and what does it hide?
Try answering first
Model answer
It tells you that 90 percent of the lines, or branches, were executed while the tests ran. It says nothing about whether the results were checked.
def is_adult(age):
return age >= 18
def test_runs_but_checks_nothing():
is_adult(20) # 100% line coverage, zero assertions
What coverage hides:
- Missing assertions, as above. Executed is not verified.
- Missing code: a validation you forgot to write has no lines to cover.
- Line vs branch: a line with
ifcan be hit while one branch is never taken, so branch coverage is stricter. - Quality of inputs: boundary values and error cases may never run.
Where it helps: the uncovered 10 percent is useful, because it shows code that no test touches at all. Tools such as coverage.py, JaCoCo and go test -cover report it.
Use coverage to find gaps, and use code review or mutation testing to judge test strength.
Key points
- Coverage measures executed code, not verified behavior
- Branch coverage is stricter than line coverage
- Missing code cannot be covered
- Uncovered code reveals gaps
Likely follow-ups
- Should a pipeline fail when coverage drops below a threshold?
Common mistakes
- Treating a high coverage number as proof of good tests
- Writing assertion-free tests to raise the number