Tutorial-2: Basis Path Testing-Estimation of Complexity Measure V(G)
Basis path testing helps a tester to compute logical complexity measure, V(G), of the code. This value of V(G), defines the maximum number of test cases to be designed by identifying basis set of execution paths to ensure that all statements are executed at least once.
Steps to compute the complexity measure, V(G) are as under
Step 1: Construct the flow graph from the source code or flow charts.
Refer Following Tutorial on :
Flow Graph and its Notations
Step 2: Identify independent paths.
Step 3: Calculate Cyclomatic Complexity, V(G).
Step 4: Design the test cases.
Objective of the Tutorial: To draw a Flow Graph, find its Cyclomatic Complexity, V(G) and the independent paths for the following piece of code.
void foo (float y, float a *, int n)
{
float x = sin (y) ;
if (x > 0.01)
z = tan (x) ;
else
z = cos (x) ;
for (int i = 0 ; i < x ; + + i) {
a[i] = a[i] * z ;
Cout < < a [i] ;
}
Step 1: Let us try to provide numbering to the various nodes as per the following Flow Graph
Step 2: Piece of code being covered under Node 1
void foo (float y, float a *, int n)
{
float x = sin (y) ;
if (x > 0.01)
Step 3: Piece of code being covered under Node 2
z = tan (x) ;
else
Step 4: Piece of code being covered under Node 3
z = cos (x) ;
Step 5: Piece of code being covered under Node 4
for (int i = 0 ; i < x ; + + i)
Step 6: Piece of code being covered under Node 5
{
Step 7: Piece of code being covered under Node 6
a[i] = a[i] * z ;
Cout < < a [i] ;
}
Step 8: Piece of code being covered under Node 7
Cout < < a [i] ;
}
Step 9: Calculation of V(G) by three methods
Method 1: V(G) = e � n + 2 ( Where �e� are edges & �n� are nodes)
V(G) = 8 � 7 + 2=3
Method 2: V(G) = P + 1 (Where P- predicate nodes with out degree = 2)
V(G) = 2 + 1 = 3 (Nodes 1 and 5 are predicate nodes)
Method 3: V(G) = Number of enclosed regions + 1 = 2+1=3
V(G) = 3 and is same by all the three methods.
Conclusions from the above tutorial:
Conclusion 1: By getting a value of V(G) = 3 we conclude that it is a �well written� code, its �testability� is high and cost / effort to maintain is low.
Conclusion 2: There are 3 paths in this program which are independent paths and they form a basis-set. These paths are described below
Path 1: | 1 � 2 � 4 � 5 – 7 |
Path 2: | 1 � 3 � 4 � 5 – 7 |
Path 3: | 1 � 3 � 4 � 5 � 6 – 7 |
Conclusion � 3: We can form another basis-set as described below
Path 1: | 1 � 2 � 4 � 5 – 7 |
Path 2: | 1 � 3 � 4 � 5 – 7 |
Path 3: | 1 � 2 � 4 � 5 � 6 – 7 |
Conclusion 4: We must execute these paths at least once in order to test the program thoroughly. Accordingly we can design the test cases.
Many more Articles & Tutorials on White Box Testing

An expert on R&D, Online Training and Publishing. He is M.Tech. (Honours) and is a part of the STG team since inception.
That\’s a smart answer to a difficult qeustoin.