Professional Documents
Culture Documents
Ch2 3
Ch2 3
Chapter 2.3
Graph Coverage for Source Code
www.introsoftwaretesting.com
Overview
if (x < y)
{ 1
return; x<y
} x >= y
return 2
print (x);
return;
print (x)
3 return
x = 0;
x=0 1
while (x < y) dummy node
{
2
y = f (x, y); x<y x >= y implicitly
x = x + 1; x=0 1
initializes loop
} 3 4
y =f(x,y)
x=x+1 2
x<y x >= y
for (x = 0; x < y; x++)
{ y = f (x, y) 3 5
y = f (x, y);
}
4 x=x+1
implicitly
increments loop
Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com © Ammann & Offutt 7
CFG : The case (switch) Structure
read ( c) ;
switch ( c )
{
case ‘N’: 1 read ( c );
y = 25; c == ‘N’
break; c == ‘Y’ default
case ‘Y’:
y = 50; 2 3 4
y = 25; y = 0;
break; break; y = 50; break;
break;
default:
y = 0; 5
break; print (y);
}
print (y);
sum = 0;
for (int i = 0; i < length; i++)
{
sum += numbers [ i ];
}
med = numbers [ length / 2 ];
mean = sum / (double) length;
varsum = 0;
for (int i = 0; i < length; i++)
{
varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean));
}
var = varsum / ( length - 1.0 );
sd = Math.sqrt ( var );
sum = 0;
for (int i = 0; i < length; i++) 2 i=0
{
sum += numbers [ i ];
}
med = numbers [ length / 2 ]; i >= length
mean = sum / (double) length; 3
varsum = 0; i < length
for (int i = 0; i < length; i++)
{ i++ 4
varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean)); 5
} i=0
var = varsum / ( length - 1.0 );
sd = Math.sqrt ( var );
6
System.out.println ("length: " + length);
System.out.println ("mean: " + mean); i < length
System.out.println ("median: " + med); i >= length
System.out.println ("variance: " + var);
System.out.println ("standard deviation: " + sd); 7 8
} i++
Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com © Ammann & Offutt 10
Control Flow TRs and Test Paths – EC
1
Edge Coverage
2 TR Test Path
A. [ 1, 2 ] [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ]
B. [ 2, 3 ]
3
C. [ 3, 4 ]
4
D. [ 3, 5 ]
5 E. [ 4, 3 ]
F. [ 5, 6 ]
G. [ 6, 7 ]
6 H. [ 6, 8 ]
I. [ 7, 6 ]
7 8
Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com © Ammann & Offutt 11
Control Flow TRs and Test Paths – EPC
1 Edge-Pair Coverage
TR Test Paths
2 A. [ 1, 2, 3 ] i. [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ]
B. [ 2, 3, 4 ] ii. [ 1, 2, 3, 5, 6, 8 ]
C. [ 2, 3, 5 ] iii. [ 1, 2, 3, 4, 3, 4, 3, 5, 6, 7,
3 D. [ 3, 4, 3 ] 6, 7, 6, 8 ]
E. [ 3, 5, 6 ]
4 F. [ 4, 3, 5 ] TP TRs toured sidetrips
5
G. [ 5, 6, 7 ] i A, B, D, E, F, G, I J C, H
H. [ 5, 6, 8 ] ii A, C, E, H
6 I. [ 6, 7, 6 ] iii A, B, C, D, E, F, G, H
I, J, K, L
J. [ 7, 6, 8 ]
K. [ 4, 3, 4 ]
7 8 L. [ 7, 6, 7 ]
Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com © Ammann & Offutt 12
Control Flow TRs and Test Paths – PPC
Prime Path Coverage
1
TR Test Paths
A. [ 3, 4, 3 ] i. [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ]
2 B. [ 4, 3, 4 ] ii. [ 1, 2, 3, 4, 3, 4, 3,
C. [ 7, 6, 7 ] 5, 6, 7, 6, 7, 6, 8 ]
D. [ 7, 6, 8 ] iii. [ 1, 2, 3, 4, 3, 5, 6, 8 ]
3 E. [ 6, 7, 6 ] iv. [ 1, 2, 3, 5, 6, 7, 6, 8 ]
F. [ 1, 2, 3, 4 ] v. [ 1, 2, 3, 5, 6, 8 ]
4
5 G. [ 4, 3, 5, 6, 7 ]
TP TRs toured sidetrips
H. [ 4, 3, 5, 6, 8 ]
i A, D, E, F, G H, I, J
I. [ 1, 2, 3, 5, 6, 7 ]
6 J. [ 1, 2, 3, 5, 6, 8 ] ii A, B, C, D, E, F, G, H, I, J
iii A, F, H J
iv D, E, F, I J
7 8 v J
Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com © Ammann & Offutt 13
Data Flow Coverage for Source
• def : a location where a value is stored into memory
– x appears on the left side of an assignment (x = 44;)
– x is an actual parameter in a call and the method changes its value
– x is a formal parameter of a method (implicit def when method starts)
– x is an input to a program
• use : a location where variable’s value is accessed
– x appears on the right side of an assignment
– x appears in a conditional test
– x is an actual parameter to a method
– x is an output of the program
– x is an output of a method in a return statement
• If a def and a use appear on the same node, then it is only a DU-
pair if the def occurs after the use and the node is in a loop
sum = 0;
for (int i = 0; i < length; i++)
{
sum += numbers [ i ];
}
med = numbers [ length / 2 ];
mean = sum / (double) length;
varsum = 0;
for (int i = 0; i < length; i++)
{
varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean));
}
var = varsum / ( length - 1.0 );
sd = Math.sqrt ( var );
2 i=0
3 i >= length
i < length
med = numbers [ length / 2 ]
4 5 mean = sum / (double) length;
varsum = 0
sum += numbers [ i ]
i=0
i++
6 i >= length
i < length
var = varsum / ( length - 1.0 )
7 8 sd = Math.sqrt ( var )
varsum = … print (length, mean, med, var, sd)
i++
Introduction to Software Testing (Ch 2), www.introsoftwaretesting.com © Ammann & Offutt 16
CFG for Stats – With Defs & Uses
1 def (1) = { numbers, sum, length }
2 def (2) = { i }
[ 1, 2, 3, 4 ] [ 4, 3, 4 ]
[ 1, 2, 3, 5 ] [ 4, 3, 5 ]
[ 1, 2, 3, 5, 6, 7 ] [ 5, 6, 7 ]
[ 1, 2, 3, 5, 6, 8 ] [ 5, 6, 8 ]
[ 2, 3, 4 ] [ 7, 6, 7 ]
[ 2, 3, 5 ] [ 7, 6, 8 ]