Escolar Documentos
Profissional Documentos
Cultura Documentos
Software Testing
Most commonly y 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
Specialized testing
Failure F Failure: il : Manifestation M if t ti of f one or more f faults lt i in 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 ?
T T
T T
Equivalence Classes
x2 g f
x1
x1
x1
x1
x1
Example
E Example: l i input t condition diti 0 <= < x <= < max
valid equivalence class : 0 <= x <= max invalid equivalence classes : x < 0, x > max 3 test t t cases
two invalid (none, more than N) one (e.g. any value not in valid input set ) one (e.g. it is not a letter)
one valid Eq. class for each value (total n) one (e.g. it is a letter)
x1
x1
a Robustness Testing
x1
b Worse-Case Testing
x1
x1
Example
C Consider id a program with ith th the f following: 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
not
C1
or and
E1
not
C2
E2
and
C3
and and
E3
and
C4
E5
and
and
E4
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 E1 E2 E3 E4 E5
0 0 1
1 0 1
1 1 0
1 1 1
1 1 1
1 1 1
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
1
1 2 3 4 5 67 exit
TER (Test Effectiveness Ratio) TER = Coverage achieved = statements exercised / total statements
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 b be 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
c
X = X/ A
F b
A=2 or X>1
F d
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 a
A>1 and B=0
c
X = X/ A
b
A=2 or X>1
Test cases:
1) A = 1, B = 0, X = 3 2) A = 2, B = 1, X = 1 (abe) abe) (abe) abe b )
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
c
X = X/ A
F b
A=2 or X>1
Test cases:
1) A = 2, B = 0, X = 4 (ace) ( ) 2) A = 1, B = 1, X = 1 (abd) d
Y
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
a
A>1 and B=0
c
X = X/ A
F b
A=2 or 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)
X = X+1
Example p
1
V(G) = 6 regions
2
R4
3 4 5
R6
R1
10 11 R5 13
6 7
R2 R3
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 l loop 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
Implications ...
T Test Testt-case design d i
careful selection of a subset of all possible test cases The e objec objective es should ou d be to o maximize a e the e number of errors found by a small finite number of test cases
A good test case is one likely to show an error. Description p of expected p output p or result is an essential part of testtest-case definition. A programmer should avoid attempting to test his/her own program. testing is more effective and successful if performed by an Independent Test Team.
Avoid onon-thethe-fly testing. Document all test cases. Test valid as well as invalid cases. Th Thoroughly hl i inspect t all ll t test t results. lt More o e detected e errors o s implies p es e even e more oe errors present.
Decide in advance when to stop testing Do not plan testing effort under the tacit assumption that no errors will be found. Testing is an extremely creative and intellectually y challenging g g task.
Summary
Testing can show the presence of bugs bugs, but not their absence E h Exhaustive ti t testing ti i is generally ll not t possible ibl Testing Strategies
White-box Black-box