Introduction
When writing tests for software, it can be hard to know if you have tested enough. Test coverage metrics help solve this by measuring how much of the code is actually checked by tests. This helps find gaps where bugs might hide.
Imagine cleaning a house and wanting to know how much you cleaned. Line coverage is like checking which rooms you entered. Branch coverage is like checking if you cleaned both sides of a door. Function coverage is like checking if you cleaned every room. But just entering a room doesn’t mean you cleaned it well.
┌───────────────────────────────┐
│ Test Coverage │
├───────────────┬───────────────┤
│ Line Coverage │ Branch Coverage│
│ (Lines run) │ (Paths tested) │
├───────────────┼───────────────┤
│ Function Cover│ Statement Cover│
│ (Functions run)│ (Statements run)│
└───────────────┴───────────────┘
↓
Limitations: Coverage ≠ Qualitydef is_even(n): if n % 2 == 0: return True else: return False print(is_even(4)) print(is_even(5))