Software Testing · Software Engineering

Path Testing

Watch lectures

Path Testing (Basis Path Testing)

Definition

Path Testing is a white-box testing technique that derives test cases to ensure every independent (linearly independent) path through the program's Control Flow Graph is executed at least once — based directly on Cyclomatic Complexity.

Process (McCabe's Basis Path Testing Method)

Step 1: Draw the Control Flow Graph (CFG)

Convert the code into its CFG (nodes = statements/blocks, edges = control flow)

Step 2: Compute Cyclomatic Complexity

V(G) = E − N + 2   (or)   V(G) = D + 1

This gives the number of independent paths needed.

Step 3: Identify the Independent Paths (Basis Set)

List V(G) linearly independent paths through the CFG — each path introduces at least one new edge not covered by previous paths.

Step 4: Design Test Cases

Create one test case for each independent path, ensuring the input drives execution along that specific path.

Example

For code with 2 decision points (if/else nested once):

V(G) = D + 1 = 2 + 1 = 3

→ Need 3 test cases, each covering one distinct path through the CFG (e.g., Path 1: both conditions true; Path 2: first true second false; Path 3: first false).

Why Path Testing Matters

  • Guarantees a known minimum level of code coverage (every independent path executed at least once)
  • Directly tied to Cyclomatic Complexity — gives an objective, calculable number of required test cases
  • Helps identify unreachable/dead code (a path that can never be constructed)

Advantages

  • Systematic, mathematically grounded (not guesswork)
  • Ensures every decision branch is exercised
  • Good defect-detection for logic errors within a module

Disadvantages

  • Doesn't test all possible combinations of paths (only a basis/independent set) — some combined-condition bugs may be missed
  • Requires access to source code (white-box) — not usable for black-box testing
  • Complex for very large/highly branched functions

Relationship to Other Topics

  • Uses the Control Flow Graph (constructed as covered earlier)
  • Test case count = Cyclomatic Complexity V(G)

Exam tip: A classic combined numerical question: "Given this code, draw the CFG, compute V(G), and list the independent test paths" — practice all three steps together, since they're usually asked as one multi-part question.

Free AppAndroid App

Coursify Android App

Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.

← All Software Engineering modules