Page 208 - DCAP405_SOFTWARE_ENGINEERING
P. 208
Unit 12: Testing Tactics
Notes
Notes Note that each new path introduces a new edge.
The path 1-2-3-4-5-10-1-2-3-6-8-9-10-1-11 is not considered to be an independent path because
it is simply a combination of already specified paths and does not traverse any new edges.
Paths 1, 2, 3, and 4 constitute a basis set for the flow graph in Figure 12.2 (B).
That is, if tests can be designed to force execution of these paths (a basis set), every statement in
the program will have been guaranteed to be executed at least one time and every condition will
have been executed on its true and false sides. It should be noted that the basis set is not unique.
In fact, a number of different basis sets can be derived for a given procedural design.
How do we know how many paths to look for? The computation of cyclomatic complexity
provides the answer. Cyclomatic complexity has a foundation in graph theory and provides us
with an extremely useful software metric. Complexity is computed in one of three ways:
1. The number 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
is the number of flow graph edges, N is the number of flow graph nodes.
3. Cyclomatic complexity, V(G), for a flow graph, G, is also defined as V(G) = P + 1 where P
is the number of predicate nodes contained in the flow graph G.
Referring once more to the flow graph in Figure 12.2 (B), the cyclomatic complexity can be
computed using each of the algorithms just noted:
1. The flow graph has four regions.
2. V(G) = 11 edges – 9 nodes + 2 = 4.
3. V(G) = 3 predicate nodes + 1 = 4.
Therefore, the cyclomatic complexity of the flow graph in Figure 12.2 (B) is 4.
More important, the value for V(G) provides us with an upper bound for the number of
independent paths that form the basis set and, by implication, an upper bound on the number of
tests that must be designed and executed to guarantee coverage of all program statements.
Deriving Test Cases
1. Using the design or code as a foundation, draw a corresponding flow graph. A flow graph
is created using the symbols and construction rules. Referring to the PDL for average in
Figure 12.3 (A), a flow graph is created by numbering those PDL statements that will
be mapped into corresponding flow graph nodes. The corresponding flow graph is in
Figure 12.3 (B).
LOVELY PROFESSIONAL UNIVERSITY 201