Course contentsShow
← Software Engineering
Lesson 589 of 1,93318. Test CoverageFree lesson

Path Coverage

Understanding path coverage as testing all possible execution paths through code, and why it's often impractical.

Path Coverage

What you'll learn: You'll understand path coverage as the most thorough — but often impractical — form of test coverage.

What Is Path Coverage?

Path coverage measures whether your tests execute every possible path through your code. A "path" is a unique sequence of decisions (branches) from the start to the end of a function.

While branch coverage only checks that each if/else gets visited, path coverage considers every combination of those branches.

Why It Explodes Quickly

Consider this simple function:

def process(a, b, c):
    if a:
        do_something()
    if b:
        do_another()
    if c:
        do_third()

This has just 3 independent if statements. But it has 8 possible paths:

  • All false
  • Only a true
  • Only b true
  • Only c true
  • a and b true
  • a and c true
  • b and c true
  • All true

With each independent decision point, paths double (2^n). Ten decisions = 1,024 paths. Twenty = over a million.

The Practicality Problem

Path coverage sounds ideal — test everything! — but it's typically impossible for real code:

  • Loops create infinite paths (loop 0 times, 1 time, 2 times...)
  • Combinatorial explosion makes writing tests prohibitively expensive
  • Many paths may be logically impossible or redundant

Most teams aim for high branch coverage instead, focusing path-level testing only on critical, complex logic where specific combinations matter.

Key Takeaway: Path coverage tests all possible execution paths through code, but its exponential growth makes it impractical for most real-world scenarios — branch coverage is usually the pragmatic ceiling.