Beruflich Dokumente
Kultur Dokumente
Topic 6:
Verification: Testing and Analysis
Your Name: _____________________
Computer Science & Engineering Department
The Chinese University of Hong Kong
Chinese University, CSE Dept.
Software Engineering / 6 - 1
Software Engineering / 6 - 2
Comparison: _______________________
Software Engineering / 6 - 3
Verifying: - code
- spec (simulation or property analysis)
- process
- the verification itself
- software quality (portability,
understandability,
performance, etc)
Verification may be performed
- at different points of time
- by different people
- with different goals
- by using different techniques
Software Engineering / 6 - 4
Software Engineering / 6 - 5
Portability
Maintainability
Reusability
Understandability
User-friendliness
__
__
A:
__
B:
__
__
Software Engineering / 6 - 6
Maintainability
hard to quantify
ask the question how, when, and why the s/w
products are likely to ______________
Software Engineering / 6 - 7
Approaches to Verification
1) Experimenting with the behavior of the
product
testing (________)
Software Engineering / 6 - 8
Software Engineering / 6 - 9
Software Engineering / 6 - 10
A Testing Example
Example 6.1 Consider the following binary search procedure:
procedure binary-search(key: in element; table: in elementTable; found: out
Boolean)
begin
bottom := tablefirst;
top := tablelast;
while bottom < top loop
if (bottom + top) rem 2 0 then
middle := (bottom + top 1) /2;
else
middle := (bottom + top)/2;
endif;
if key table(middle) then
top := middle;
else
bottom := middle + 1;
a subtle bug ->
endif;
endloop;
found := key = table(middle);
end binary-search;
Software Engineering / 6 - 11
=>
(hard to detect by_______________)
Software Engineering / 6 - 12
Software Engineering / 6 - 13
numerical precision
__________________________
ii.
timing accuracy
which are specification dependent
e.g.,
Software Engineering / 6 - 14
d1 d2
P: a program
D: Ps _________ domain
d1,d2 D
R: Ps __________ range
r1,r2 R
r2
r1 R R
OR: __________________________
Software Engineering / 6 - 15
d1 d2
r2
r1 R R
_______________________________
Chinese University, CSE Dept.
Software Engineering / 6 - 16
Software Engineering / 6 - 17
, d1 , d 2 ,...
d , d , d , d ,...
1 2
2
3
D
2F
d1 , d 2 , d 3 ,...
d1 , d 2 , d 3 , d 4
Software Engineering / 6 - 18
7)
Similar to ideal
______________________________________________
e.g. The binary search program in Example 6.1 works properly only if
the length of the sequence is a power of two.
Let di: length of the sequence is i, then
C1 = { <d5>, <d3,d4>, <d7,d8> }
C2 = { <d3,d7,d9>, <d2,d4,d8> }
Chinese University, CSE Dept.
Software Engineering / 6 - 19
________________________________________
e.g.
CB = {<x1,x2, , xn> | n 2 and exists i,j
(xi < 0, xj 0) }
CA is finer than CB
Software Engineering / 6 - 20
C1 d 3 , d 7 , d 9 , d 2 , d 4 , d 8
C2 d 3 , d 7 , d 2 , d 8
Software Engineering / 6 - 21
e.g.,
if x > y then
max := x;
else
max := y; error: y becomes another symbol
endif;
T1: { (3,2), (2,3) } uncovers the error
T2: { (3,2), (4,3), (5,1) } does not
Chinese University, CSE Dept.
Software Engineering / 6 - 22
D2
D3
4) ________________________: D = DI are
those classes, where D is the input domain
Chinese University, CSE Dept.
Software Engineering / 6 - 23
________ numbers
D2 D3
D1 D3
Software Engineering / 6 - 24
Software Engineering / 6 - 25
black-box testing
1. ____________________
2. derive test cases purely based on the spec
spec-based test case development
3. test what the program is supposed to do (for all
___________ functions)
white-box testing
1. ___________________
look at the program structure during testing
2. using information about the internal structure to derive test
cases
structure-based test case development
3. test what the program does (any ________ functions?)
Chinese University, CSE Dept.
Software Engineering / 6 - 26
White-Box Testing
Four test selection criteria (C0,C1,C2,C3)
Example 6.2: Consider the well-known algorithm of Euclid
begin
read(x);
read(y);
while x y loop
if x > y then
x := x y;
else
y := y x;
endif;
end loop;
return(x);
end;
entry
Q:
while
xy
if x > y
x=y
exit
Software Engineering / 6 - 27
Statement-Coverage Criterion
Select a test set T such that every
elementary _________ in P is executed at
least once by some d in T
an input datum executes many statements
try to minimize the number of test cases while
still preserving the desired coverage
Software Engineering / 6 - 28
Example
read (x); read (y);
if x > 0 then
write ("1");
else
write ("2");
end if;
if y > 0 then
write ("3");
else
write ("4");
end if;
Software Engineering / 6 - 29
Software Engineering / 6 - 30
b) if-then else
c) if
G1
G1
G2
G1
G1
G2
Figure 6.1
Software Engineering / 6 - 31
c)
d)
e)
Software Engineering / 6 - 32
Software Engineering / 6 - 33
while
xy
if x > y
# nodes:_______________
# edges:_______________
# predicate nodes: _______
# regions:______________
x=y
exit
________
= ________
= ________
= V(G)
Software Engineering / 6 - 34
McCabes Theory
McCabes cyclomatic complexity V(G)
1) V(G) = e n + 2
Where in the control flow graph
e: number of edges
n: number of nodes
V(G): the number of linearly independent paths in a program (the
number of conditions plus one, if no GOTOs)
for each module
V(G): _________ good structure
upper bound
2) V(G) = # of regions
3) V(G) = # of predicate nodes + 1
Chinese University, CSE Dept.
Software Engineering / 6 - 35
Software Engineering / 6 - 36
Software Engineering / 6 - 37
Software Engineering / 6 - 38
if C1 then
if C2 then
S1;
else
S2;
S2;
endif
else
S2;
endif
Software Engineering / 6 - 39
if C1 then
if C2 then
S1;
if C3 then
else
S2;
S1; ___
C1
C2
C3
else
S2; ___
endif
else
S2; ___
endif
else
S2; ___
Software Engineering / 6 - 40
0 then
5;
x=0
x0
x=0
x0
z x;
1 then
z / x;
z>1
z1
z>1
z1
0;
test 1: {<x=0,z=1>;<x=1,z=3>}
test 2: {<x=0,z=3>;<x=1,z=1>}
Chinese University, CSE Dept.
Software Engineering / 6 - 41
Select a test set T such that all paths leading from the initial to the
final node of Ps control flow graph are traversed at least once
i. In general, the number of possible execution paths in a
program is ________________
e.g., 10 simple if statements (with simple conditions) => _____
paths!
Problem: The # of paths can be very large.
ii. Main complexity: program constructs which make paths
approaching infinite => __________________________
iii. a practical solution: look for conditions that execute loops
a) __________________ times
b) a ________ number of times
c) an _______ number of times
Chinese University, CSE Dept.
Software Engineering / 6 - 42
___________________________________________________________________________________________
Software Engineering / 6 - 43
Software Engineering / 6 - 44
(_____________ Use)
a: integer;
a := 4; _______
Software Engineering / 6 - 45
Omission errors
missing
false negative
Software Engineering / 6 - 46
Black-Box Testing
functional testing
specification-based
rigor and formality
precise operating conditions => precise input
categories
precise expected results => precise comparisons
(__________________)
Software Engineering / 6 - 47
Black-Box Testing
Two examples (practical approaches)
1) Decision table-based testing
A spec is described by a decision table
provides a ____________ of input and expected output
2) Cause-effect graphs
Structuring complex input-output specs
a special case for ________________________
Software Engineering / 6 - 48
Software Engineering / 6 - 49
true
true
true
true
____________
__________
true
true
true
SE
true
E=B
true
true
E=I
true
SE=B
true
SE=I
true
SE=B+I
Action
true
true
b,i
b,i
______________
Table 6.1 Decision table specifying the word
processor of Example 6.5
Software Engineering / 6 - 50
Software Engineering / 6 - 51
b
i
E
AND
E=B
SE
E=I
AND
SE=B
SE=I
OR
SE=B+I
Chinese University, CSE Dept.
Software Engineering / 6 - 52
Constraints
1.
2.
3.
4.
5.
e: at most one
i: at least one
o: one and only one
r: implies
m: masks
Software Engineering / 6 - 53
OR
i
E
AND
E=B
SE
E=I
AND
SE=B
SE=I
SE=B+I
OR
Software Engineering / 6 - 54
Software Engineering / 6 - 55
Boundary Conditions
Typical program errors happen at the boundary
between different classes
e.g.,
if x > y then
S1;
else
S2;
endif;
Select test cases for x > y
x < y and x = y (if ___ becomes ___)
Initial conditions
Chinese University, CSE Dept.
Software Engineering / 6 - 56
Software Engineering / 6 - 57
system testing
(delivery environment)
operational environment
Chinese University, CSE Dept.
Software Engineering / 6 - 58
Software Engineering / 6 - 59
Software Engineering / 6 - 60
Software Engineering / 6 - 61
Software Engineering / 6 - 62
Software Engineering / 6 - 63
Software Engineering / 6 - 64
STUB
PROCEDURE
UNDER TEST
CALL
DRIVER
Drivers
Stubs
Software Engineering / 6 - 65
2)
Software Engineering / 6 - 66
USES
1
USES
2,1
2,2
Software Engineering / 6 - 67
Top-down integration
Bottom-up integration
Software Engineering / 6 - 68
Sandwich integration
Build integration
Software Engineering / 6 - 69
Software Engineering / 6 - 70
x := 3;
x := 3;
Key: Properly designing and documenting test cases
to make them _________________ .
Chinese University, CSE Dept.
Software Engineering / 6 - 71
Concluding Remarks
Goals and requirements of verification
Testing schemes
Testing in the small
White-box testing
Black-box testing
Software Engineering / 6 - 72