#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
White Box Techniques

Path Coverage

What is Path Coverage?

Path coverage is the most thorough white box testing technique, requiring that every possible execution path through the code — every unique combination of branches — be tested at least once.

Why It's Challenging

The number of possible paths can grow exponentially with the number of decision points and loops, making 100% path coverage impractical for most real-world applications. Basis path testing is often used as a practical, mathematically grounded compromise.

Coverage Hierarchy

  • Statement coverage is the weakest criterion.
  • Branch coverage is stronger, subsuming statement coverage.
  • Path coverage is the strongest, subsuming both statement and branch coverage.

Worked Example: Listing Every Path

Here is a simple shipping fee function with two independent decisions.

def shipping_fee(weight, express):
    fee = 50
    if weight > 5:        # decision A
        fee += 30
    if express:           # decision B
        fee += 100
    return fee

Each decision can go true or false, and the two decisions follow one after the other, so there are 2 × 2 = 4 complete paths from entry to exit.

PathABTest inputExpected fee
1TrueTrueweight 8, express True180
2TrueFalseweight 8, express False80
3FalseTrueweight 2, express True150
4FalseFalseweight 2, express False50

Statement, Branch and Path Coverage on the Same Code

  • Statement coverage: test 1 alone runs every line.
  • Branch coverage: tests 1 and 4 together take each decision both ways.
  • Path coverage: all four tests are needed.

Why would the extra two tests matter? Imagine a later change makes the express charge depend on the weight surcharge already being added. A bug that appears only when A is true and B is false would slip through branch coverage but would be caught by path 2. Path coverage checks how decisions interact, not just each decision alone.

Why Paths Multiply So Quickly

With k independent if statements in a row, the number of paths is 2 to the power k. Three decisions give 8 paths, ten give 1,024, and twenty give over a million. Loops make it worse: a loop that can run 0 to 50 times creates a separate path for every possible count. That is why full path coverage is usually limited to small, critical functions.

Infeasible paths

Some paths look possible on a diagram but can never happen. If one condition is x > 10 and a later one is x < 5, with x unchanged in between, the path where both are true is impossible. Mark such paths as infeasible and record why, rather than trying to force a test.

Practical Ways to Apply Path Coverage

  1. Pick functions where combinations of decisions matter: pricing rules, eligibility checks, safety logic.
  2. Draw the control flow graph and list every path, or use a tool that does it for you.
  3. For loops, test zero iterations, one iteration, a typical number and the maximum, instead of every count.
  4. Remove infeasible paths, then write one test per remaining path with an exact expected result.
  5. Where the path count is still too large, fall back to basis path testing, which needs only as many tests as the cyclomatic complexity.

Common mistake: claiming path coverage because every branch was tested. Branch coverage and path coverage are equal only when there is a single decision.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course