You are on page 1of 3

# White Box Testing 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 Tutorial on “ What is a Flow Graph & Understand its Notations”)

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

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

if (x > 0.01)

z = tan (x) ;

else

z = cos (x) ;

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

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

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