Source Code > Flow Graph > V(G)
(Cyclomatic Complexity > Set of Linearly Independent paths)The technique is to divide the code into nodes.
The sequential statement are assigned a single node.Each Condition has a separate node if logical operators (
&&
and||
etc) are used in case of a for loop / if else
In this way, a node tree is constructed representing a flow of program.
Predicate Node
Any node which has more than one outgoing node
Cyclomatic Complexity
V(G)
Determines how complex the code / function is.
If we are to test all bunch of code, we should go for regions with more cyclomatic complexity
- = E - N + 2 → Edges - Nodes + 2
- = P + 1 → Predicate Node + 1
- = R → Regions
All formulas should give us a same final answer except case of some specific cases (switch cases)
In case of our example:
- = 11 - 9 + 2 = 4
- 3 + 1 = 4
- 4
Paths
Determine the paths
Be default the first path is linearly independent
100% Test Coverage
We need to maintain a history of paths
Set of Basis Path
In case of our example:
S# | Paths | History Check |
---|---|---|
1 | 1→2→5→6→7→9 | |
2 | 1→2→5→6→7→8→7→9 | 7→8→7 |
3 | 1→2→3→5→6→7→9 | 2→3→5 |
4 | 1→2→3→4→6→7→9 | 3→4, 4→6 |
Line Coverage < Branch Coverage < Path Coverage