Testing Tactics
Testing Tactics
R4
1 1
2 2
3 R3
3
6 4 6 4
R2
7 8 5
7 R1 8 5
9
9
11 10 11 10
Independent Program Paths
• Defined as a path through the program from the start node until the
end node that introduces at least one new set of processing
statements or a new condition (i.e., new nodes)
• Must move along at least one edge that has not been traversed
before by a previous path
• Basis set for flow graph on previous slide
– Path 1: 0-1-11
– Path 2: 0-1-2-3-4-5-10-1-11
– Path 3: 0-1-2-3-6-8-9-10-1-11
– Path 4: 0-1-2-3-6-7-9-10-1-11
• The number of paths in the basis set is determined by the cyclomatic
complexity
Cyclomatic Complexity
• Provides a quantitative measure of the logical complexity of a program
• Defines the number of independent paths in the basis set
• Provides an upper bound for the number of tests that must be conducted
to ensure all statements have been executed at least once
• Can be computed three ways
– The number of regions
– V(G) = E – N + 2, where E is the number of edges and N is the number of nodes
in graph G
– V(G) = P + 1, where P is the number of predicate nodes in the flow graph G
• Results in the following equations for the example flow graph
– Number of regions = 4
– V(G) = 14 edges – 12 nodes + 2 = 4
– V(G) = 3 predicate nodes + 1 = 4
Deriving the Basis Set and Test Cases
1) Using the design or code as a foundation, draw a corresponding flow
graph
2) Determine the cyclomatic complexity of the resultant flow graph
3) Determine a basis set of linearly independent paths
4) Prepare test cases that will force execution of each path in the basis set
A Second Flow Graph Example
1 int functionY(void) 3
2 {
3 int x = 0; 4
4 int y = 19;
5 A: x++; 5
6 if (x > 999)
7 goto D;
8 if (x % 11 == 0) 6
9 goto B;
0 else goto A; 8 7
1 B: if (x % y == 0) 10 9 16
2 goto C;
3 else goto A;
11 17
4 C: printf("%d\n", x);
5 goto A; 13 12
6 D: printf("End of list\n");
7 return 0; 14
8 }
15
A Sample Function to Diagram and Analyze
1 int functionZ(int y)
2 {
3 int x = 0;
0 printf("End of list\n");
1 return 0;
2 } // End functionZ
A Sample Function to Diagram and Analyze
1 int functionZ(int y) 3
2 {
3 int x = 0;
4
4 while (x <= (y * y))
5 { 6 7
6 if ((x % 11 == 0) &&
7 (x % y == 0))
9
8
9
{
printf(“%d”, x);
12 13
0 x++;
1 } // End if 10
2 else if ((x % 7 == 0) || 15
3 (x % y == 1))
4 { 16
5 printf(“%d”, y);
6 x = x + 2; 18
7 } // End else
8 printf(“\n”);
9 } // End while 20
0 printf("End of list\n"); 21
1 return 0;
2 } // End functionZ
Loop Testing - General
• A white-box testing technique that focuses exclusively on the validity of
loop constructs
• Four different classes of loops exist
– Simple loops
– Nested loops
– Concatenated loops
– Unstructured loops
• Testing occurs by varying the loop boundary values
– Examples: