Software Testing Techniques
Software Testing Techniques
g Testing
g
Techniques
Software Testing
Most commonlyy used method for Software Validation
Executing the code under test (CUT) with a set of test
cases and observing the behavior
Different from static approaches
Different levels
Unit
Integration
System
Acceptance Testing
Te ting strategies
Testing
t tegie
Specification-base
Specificationbased
d (black(black-box)
Code based (white
(white--box)
Specialized testing
if (a<b) {foo(a,b);}
if (a>b) {foo(a,b);}
{foo(a b);}
Failure
F
Failure:
il : Manifestation
M if t ti off one or more ffaults
lt iin
the observed program behavior
Failure
Incorrect program behavior due to a fault in the
program.
Failure can be determined only with respect to a
set of requirement specifications.
specifications.
A necessary condition for a failure to occur is
that execution of the program force the
erroneous portion of the program to be
executed.
Sufficient condition?
Testing ?
White--box testing
White
T
T
T
T
Equivalence Classes
x2
g
f
x1
W k Normal
Weak
N
l Equivalence
E i l
Class
Cl
Testing
T ti
x1
x1
St
Strong
N
Normal
l Equivalence
E i l
Class
Cl
Testing
T ti
W k Robust
Weak
R b t Equivalence
E i l
Class
Cl
Testing
T ti
x1
x1
St
Strong
R b t Equivalence
Robust
E i l
Class
Cl
Testing
T ti
Example
E
Example:
l iinputt condition
diti
0 <=
< x <=
< max
two invalid
(none, more than N)
one
(e.g. any value not
in valid input set )
one
(e.g. it is a letter)
one
(e.g. it is not a letter)
x1
x1
b
Robustness Testing
x1
x1
Worse-Case Testing
x1
Example
C
Consider
id a program with
ith th
the ffollowing:
ll i
input conditions
C1: command is credit
C2: command is debit
C3: A/C is valid
C4: Transaction amount
not valid
Output conditions
E1
E1: print invalid command
E
E2
2: print invalid A/C
E
E3
3: print debit amount not valid
E4
E4: debit A/C
E5: credit A/C
Example:
p CauseCause-Effect Graph
p
input conditions
C1: command is credit
Output conditions
E1: print invalid command
E
E2
2: print invalid A/C
not valid
not
or
E1
and
E2
C1
not
C2
and
and
E3
and
E5
and
E4
C3
and
C4
and
Example
p
Decision table showing the combinations of input conditions
that make an effect true.
true (summarized from Cause Effect
Graph)
Write test cases to exercise each Rule in decision Table.
Example:
C1
C2
C3
C4
0
0
-
E1
E2
E3
E4
E5
1
0
-
1
1
0
1
1
1
1
1
1
1
1
1
1
Control--Flow Testing
Control
D t Flow
Data
Fl
Testing
T ti
Statement coverage
Decision coverage
Condition coverage
Decision--condition
Decision
coverage
Multiple condition coverage
B i P
Basis
Path
th T
Testing
ti
Loop testing
All p-use
All c-use
All d-use
All uses
read x,y;
2 z:=1;
3 while not y=0
y 0 do
4 if x mod 2 =1
5 z:
z:=z*x
z x
6 y:=y/2
7 x:=x*x
end
2
3
exit
4
5
67
Example
void function eval (int A, int B, int X )
{
if ( A > 1) and ( B = 0 )
X = X / A;;
then
if ( A = 2 ) or ( X > 1)
then
X = X + 1;
}
Statement coverage test cases:
1) A = 2, B = 0, X = ? ( X can bbe assigned
i
d any value)
l )
Example
p
void function eval (int A, int B, int X )
{
if ( A > 1) and ( B = 0 ) then
X = X / A;
A
if ( A = 2 ) or ( X > 1) then
X = X + 1;
}
a
A>1
and
B=0
F
X = X/ A
b
A=2
or
X>1
1) A = 3,
3 B = 0,
0 X = 1 (acd)
2) A = 2, B = 1, X = ? (abe)
X = X+1
Example
p
Condition coverage
g test
cases must cover conditions
A>1, A<=
A>1
A<=1
1, B=
B=0
0, B !=
!=0
0
A=2
A=
2, A !=
!=2
2, X >
>1
1, X<=
X<=1
1
Test cases:
1) A = 1, B = 0, X = 3
2) A = 2, B = 1, X = 1
(abe)
abe)
(abe)
abe
b )
a
A>1
and
B=0
X = X/ A
b
A=2
or
X>1
X = X+1
Example
Decision Condition coverage
test cases must cover
conditions
A>1, A<=
A>1
A<=1
1, B=
B=0
0, B !=
!=0
0
A=2
A=
2, A !=2
!=2, X >1
>1, X<=1
X<=1
and
also ( A > 1 and B = 0) T,, F
( A = 2 or X > 1) T, F
a
A>1
and
B=0
F
X = X/ A
b
A=2
or
X>1
Test cases:
1) A = 2, B = 0, X = 4 (ace)
(
)
2) A = 1, B = 1, X = 1 (abd)
X = X+1
Example
Multiple Condition coverage
must cover conditions
1)
2)
3)
4)
A>
>1
1, B =0
=0
A>
>1
1, B !=0
!=0
A<=
A<=1
1, B=0
B=0
A <=
<=1
1, B!=0
B!=0
5)
5)
6)
6)
7)
7)
8
8))
A=2
A=2, X>1
X>1
A=2
A=2, X <=1
<=1
A!=2
A!=2, X > 1
A !=2
!=2, X<=1
X<=1
Test cases:
1)
2)
3)
4)
A = 2,
A = 2,
A = 1,
A = 1,
B = 0, X = 4
B = 1, X = 1
B = 0, X = 2
B = 1, X = 1
(
(covers
1,5)
(covers 2,6)
(covers 3,7)
(covers 4,8)
a
A>1
and
B=0
F
X = X/ A
b
A=2
or
X>1
X = X+1
Example
p
1
V(G) = 6 regions
2
3
R4
R1
4
R6
5
6
10
R2
R3
11
R5
13
12
6 linearly
independent paths
Loop Testing
Aims to expose bugs in loops
Fundamental Loop Test criteria
1)
2)
3)
4)
bypass
b pass the loop altogether
one pass through the loop
t
two
passes through
th
h th
the lloop b
before
f
exiting
iti
a typical number of passes through the loop, unless
covered by some other test
5) max number of passes (loop exit condition in farfarloop)
Loop Testing
Nested loops
1) Set all but one loop to a typical value and run
through the single
single--loop cases for that loop. Repeat
for all loops.
2) Do minimum values for all loops simultaneously.
3) Set all loops but one to the minimum value and
repeat the test cases for that loop. Repeat for all
loops.
loops
4) Do maximum looping values for all loops
simultaneously.
simultaneously
I Complete
Is
C
l t Testing
T ti Possible
P ibl ?
Exhaustive Black
Black--box testing is generally
not possible because the input domain for a
program may be infinite
f
or incredibly large.
Exhaustive WhiteWhite-box testing is generally
nott possible
ibl b
because a program usually
ll
has a very large number of paths.
Implications ...
T
Test
Testt-case design
d i
careful selection of a subset of all possible
test cases
The
e objec
objective
e sshould
ou d be to
o maximize
a
e the
e
number of errors found by a small finite
number of test cases
Test--completion criteria
Test
Testing Principles (3
(3)
--- Glen Myers
Summary
Testing can show the presence of bugs
bugs, but not
their absence
E h
Exhaustive
ti ttesting
ti iis generally
ll nott possible
ibl
Testing Strategies
White-box
Black-box