Tutorials Hut

• # 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

• 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.
`For example:if a>b//do somethingelse//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:

1. The numbers of regions of the flow graph correspond to the Cyclomatic complexity.

2. 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.

3. 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.

• 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

`Read AÂ Â Read BÂ  IF A+B > 50Â THENÂ Â Print "Large"Â Â ENDIFÂ  If A+B<50Â THENÂ Â Print "Small"Â Â ENDIF`
PathCoverage ensures covering of all the paths from start to end.
All possible paths are-
1-3-5-7
1-3-5-6-8
1-2-4-5-6-8
1-2-4-5-7

So PathCoverage is 4.