8/6/2019 White Box 2_new
1/44
2. Path Coverage:
In this we split the program into number of distinct paths. A
program can start from the beginning and take any of thepaths to its completion.
Path Coverage= (Total paths exercised/Total no. of paths
in a program)*100
Path Testing:
Path testing is the name given to a group of test
techniques based on judiciously selecting a set of testpaths through the program. If the set of paths is properly
chosen, then it means that we have achieved some
measure of test thoroughness.
8/6/2019 White Box 2_new
2/44
This type of testing involves:
1. generating a set of paths that will cover every branch in
the program.
2. finding a set of test cases that will execute every path in
the set of program paths.
8/6/2019 White Box 2_new
3/44
Flow Graph:The control flow of a program can be analyzed using a
graphical representation known as flow graph. The flow graphis a directed graph in which nodes are either entire statements
or fragments of a statement, and edges represent flow of
control.
Fig. : The basicconstruct of the flow graph
8/6/2019 White Box 2_new
4/44
8/6/2019 White Box 2_new
5/44
8/6/2019 White Box 2_new
6/44
8/6/2019 White Box 2_new
7/44
8/6/2019 White Box 2_new
8/44
8/6/2019 White Box 2_new
9/44
8/6/2019 White Box 2_new
10/44
DD Path GraphThe DD Path graph is known as decision to decision path
graph. Here, we concentrate only on decision nodes. Thenodes of flow graph, which are in a sequence are combined
into a single node.
8/6/2019 White Box 2_new
11/44
8/6/2019 White Box 2_new
12/44
8/6/2019 White Box 2_new
13/44
8/6/2019 White Box 2_new
14/44
8/6/2019 White Box 2_new
15/44
Fig. 18: Independent paths of prev
ious date prob
lem
8/6/2019 White Box 2_new
16/44
16
Structured testing is based on the pioneering work of Tom
McCabe. It uses an analysis of the topology of the control flow
graph to identify test cases.
o Derive the control flow graph from the software module.
The structured testing process consists of the following steps:
o Compute the graph's Cyclomatic Complexity (C).
o Select a set of C basis paths.
o Create a test case for each basis path.
o Execute these tests.
8/6/2019 White Box 2_new
17/44
17
Consider the following control flow graph:
An example control flow graph.
8/6/2019 White Box 2_new
18/44
18
McCabe defines the Cyclomatic Complexity (C) of a graph as
C = edges - nodes + 2P
Edges are the arrows, and nodes are the bubbles on the
graph, P are the connected components.
Here, edges=24, nodes=19, cyclomatic complex= 24-19+2=7
In some cases this computation can be simplified. If all
decisions in the graph are binary (they have exactly twoedges flowing out), and there are p binary decisions, then
C = p+1
8/6/2019 White Box 2_new
19/44
19
Two alternate methods are available for the complexity calculations.
1. Cyclomatic complexity V(G) of a flow graph G is equal to the number of
predicate (decision) nodes plus one.
V(G)= +1
Where is the number of predicate nodes contained in the flow graph G.
2. Cyclomatic complexity is equal to the number of regions of the flow
graph.
8/6/2019 White Box 2_new
20/44
20
Consider a flow graph given in Fig. and calculate the cyclomatic complexity by
all three methods.
8/6/2019 White Box 2_new
21/44
21
Solution
Cyclomatic complexity can be calculated by any of the three methods.
1. V(G) = e n + 2P
= 13 10 + 2 = 5
2. V(G) = + 1
= 4 + 1 = 5
3. V(G) = number of regions
= 5
Therefore, complexity value of a flow graph in Fig. 23 is 5.
8/6/2019 White Box 2_new
22/44
22
Cyclomatic Complexity is exactly the minimum number of
independent, nonlooping paths (called basis paths) that can,
in linear combination, generate all possible paths through the
module.
In terms of a flow graph, each basis path traverses at leastone edge that no other path does.
McCabe's structured testing technique calls for creating C test
cases, one for each basis path.
Important: Creating and executing C test cases, based on the
basis paths, guarantees both branch and statement coverage.
8/6/2019 White Box 2_new
23/44
23
A process for creating a set of basis paths is given by McCabe:
1. Pick a "baseline" path. This
path should be a
reasonably "typical" path of
execution rather than anexception processing path.
The best choice would be
the most important path
from the tester's view.
The chosen baseline basis path
ABDEGKMQS
8/6/2019 White Box 2_new
24/44
24
2. To choose the next path,
change the outcome of the first
decision along the baseline
path while keeping the
maximum number of otherdecisions the same as the
baseline path.
The second basis path ACDEGKMQS
8/6/2019 White Box 2_new
25/44
25
3. To generate the third path,
begin again with the
baseline but vary the
second decision rather than
the first.
The third basis path ABDFILORS
8/6/2019 White Box 2_new
26/44
26
4. To generate the fourth path,
begin again with the
baseline but vary the third
decision rather than the
second. Continue varyingeach decision, one by one,
until the bottom of the
graph is reached.
The fourth basis path ABDEHKMQS
8/6/2019 White Box 2_new
27/44
27
The fifth basis path ABDEGKNQS
8/6/2019 White Box 2_new
28/44
28
5. Now that all decisions
along the baseline path
have been flipped, we
proceed to the second
path, flipping its decisions,one by one. This pattern is
continued until the basis
path set is complete.
The sixth basis path ACDFJLORS
8/6/2019 White Box 2_new
29/44
29
The seventh basis path ACDFILPRS
8/6/2019 White Box 2_new
30/44
30
Thus, a set of basis paths for this graph are:
ABDEGKMQS
ACDEGKMQS
ABDFILORS
ABDEHKMQS
ABDEGKNQS
ACDFJLORS
ACDFILPRS
8/6/2019 White Box 2_new
31/44
Example 13
Consider the problem for the determination of the nature ofroots of a quadratic equation. Its input a triple of positive
integers (say a,b,c) and value may be from interval [0,100].
The program is given in fig. 19. The output may have one of
the following words:
[Not a quadratic equation; real roots; Imaginary roots; Equal
roots]
Draw the flow graph and DD path graph. Also find
independent paths from the DD Path graph.
8/6/2019 White Box 2_new
32/44
8/6/2019 White Box 2_new
33/44
Fig. 19: Code of quadratic equation problem
8/6/2019 White Box 2_new
34/44
Fig. 19 (a): Program flow graph
8/6/2019 White Box 2_new
35/44
Fig. 19 (b): DD Path graph
ABCDEFGHIJNRS
ABGHIJNRS
ABCDFGHIJNRS
ABGHIKLNRS
ABGHIKMNRS
ABGOPRS
ABGOQRS
8/6/2019 White Box 2_new
36/44
The mapping table forDD path graph is:
8/6/2019 White Box 2_new
37/44
Independent paths are:
(i) ABGOQRS (ii) ABGOPRS(iii) ABCDFGOQRS (iv) ABCDEFGOPRS
(v) ABGHIJNRS (vi) ABGHIKLNRS
(vi) ABGHIKMNRS
8/6/2019 White Box 2_new
38/44
Example 14
Consider a program given in Fig.20 for the classification of a
triangle. Its input is a triple of positive integers (say a,b,c) from
the interval [1,100]. The output may be [Scalene, Isosceles,
Equilateral, Not a triangle].
Draw the flow graph & DD Path graph. Also find the
independent paths from the DD Path graph.
8/6/2019 White Box 2_new
39/44
8/6/2019 White Box 2_new
40/44
Fig. 20 : Code of tr
iang
lecl
assific
ation prob
lem
8/6/2019 White Box 2_new
41/44
Solution : Flow graph of triangle problem is:
Fig. 20 (a): Program flow graph
8/6/2019 White Box 2_new
42/44
The mapping table forDD path graph is:
8/6/2019 White Box 2_new
43/44
8/6/2019 White Box 2_new
44/44
Fig. 20 (b): DD Path graph
Independent paths are:i. ABFGNPQR
ii. ABFGNOQR
iii. ABCEGNPQR
iv. ABCDEGNOQR
v. ABFGHIMQR
vi. ABFGHJKMQR
vii. ABFGHJMQR