2076 10

CSC375 ยท 2076 ยท 5 marks

Discuss path testing with suitable example.

Discuss path testing with suitable example. [5]

Software EngineeringChapter 8: Software TestingDevelopment Testing

Quick answer

Path testing is a white-box (structural) testing technique that aims to design test cases such that every possible path through a program's control flow graph (CFG) is executed at least once. The goal is to ensure complete coverage of all independent paths in the program logic, thereby detecting errors in the program structure and logic.

Path Testing

Definition


Key Concepts

Control Flow Graph (CFG)

A CFG represents the program as a directed graph where:

  • Nodes represent processing steps (statements or blocks)
  • Edges represent flow of control between steps
  • Decision nodes represent branching (if, while, for)

Cyclomatic Complexity

Cyclomatic complexity (V(G)) determines the number of independent paths to be tested:

$$V(G) = E - N + 2P$$

Where:

  • E = Number of edges
  • N = Number of nodes
  • P = Number of connected components (usually 1)

Steps in Path Testing

  1. Draw the Control Flow Graph from the program
  2. Calculate Cyclomatic Complexity V(G)
  3. Identify all independent (basis) paths
  4. Design test cases for each path
  5. Execute tests and verify results

Example

Program: Find the largest of two numbers

1. Start
2. Read A, B
3. If A > B then
4.     Print "A is largest"
5. Else
6.     Print "B is largest"
7. End

Step 1: Draw the Control Flow Graph

        [1] Start
          |
        [2] Read A, B
          |
        [3] A > B ?
       /         \
    Yes            No
     |              |
    [4] Print A   [5] Print B
       \              /
        \            /
         [6] End

Step 2: Calculate Cyclomatic Complexity

ParameterValue
Edges (E)6
Nodes (N)6
P1

$$V(G) = E - N + 2P = 6 - 6 + 2(1) = \mathbf{2}$$

So there are 2 independent paths to test.

Step 3: Identify Independent Paths

PathRouteCondition
Path 11 -> 2 -> 3 -> 4 -> 6A > B (True)
Path 21 -> 2 -> 3 -> 5 -> 6A > B (False)

Step 4: Design Test Cases

Test CaseInputExpected OutputPath Covered
TC1A = 10, B = 5"A is largest"Path 1
TC2A = 3, B = 8"B is largest"Path 2

Advantages of Path Testing

  • Ensures complete logical coverage of the program
  • Helps detect unreachable code and dead code
  • Identifies logic errors that may not be found by black-box testing
  • Provides a measurable coverage criterion using cyclomatic complexity

Disadvantages

  • Becomes complex and impractical for large programs with many paths
  • Does not test data-related errors (e.g., wrong formula)
  • Number of paths can grow exponentially with nested loops and conditions

Summary

Path testing is a systematic white-box technique that guarantees all independent execution paths are tested at least once. By using cyclomatic complexity as a guide, testers can determine the minimum number of test cases required to achieve full path coverage, making it a powerful method for ensuring program correctness.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.