What is Path Coverage Testing?
Path Coverage testing is a structured testing technique for designing test cases with intention to examine all possible paths of execution at least once.
- Creating and executing tests for all possible paths results in 100% statement coverage and 100% branch coverage.
- In this type of testing every statement in the program is guaranteed to be executed at least one time. Flow Graph, Cyclomatic Complexity are used to arrive at basis path
- Cyclomatic Complexity is a software metric used to indicate the complexity of a program.
- Cyclomatic Complexity refers to the number of minimum test cases for a white boxed code which will cover every execution path in the flow.
//do something else
In the above code, cyclomatic complexity is 2 as minimum 2 test cases to cover all the possible execution path in the known code.
Cyclomatic Complexity is computed in one of three ways:
The numbers of regions of the flow graph correspond to the Cyclomatic complexity.
Cyclomatic complexity, V(G), for a flow graph G is defined as
V(G) = E – N + 2
where E = number of flow graph edges and N = is the number of flow graph nodes.
Cyclomatic complexity, V(G), for a graph flow G is also defined as
V(G) = P + 1
Where P = number of predicate nodes contained in the flow graph G.
Advantages of Path Testing:
- Path Testing helps reducing redundant tests
- Focus on program logic
- Test cases will execute every statement in a program at least once
PathCoverage = Number of Paths Covered/ Number of Total Paths
Example of Path Coverage Testing
IF A+B > 50 THEN
If A+B<50 THEN