Test Case Design
Test Case Design
CISS
Overview
What is a test case Sources for test case derivation Test case execution White box testing Flowgraphs Test criteria/coverage Statement / branch / decision / condition / path coverage Looptesting Data flow testing Def-use pairs Efficiency of different criteria
CISS
Types of Testing
CISS
V - Model
requirements
acceptance test spec
acceptance test
specification
system test
architecture spec
integration test
detailed design
module test
implementation code
unit-test
CISS
What is a Test?
Test Cases Test Data Software under Test Output
Correct result?
Oracle
How to select subset of test cases from all possible test cases with a high chance of detecting most faults ?
CISS
CISS
White-Box Testing
Testing based on program code Extent to which (source) code is executed, i.e. Covered Different kinds of coverage :
statement coverage path coverage (multiple-) condition coverage decision / branch coverage loop coverage definition-use coverage ..
CISS
CISS
if case
until
CISS
CISS
PROGRAM maxsum ( maxint, value : INT ) INT result := 0 ; i := 0 ; IF value < 0 THEN value := - value ; WHILE ( i < value ) AND ( result <= maxint ) DO i := i + 1 ; result := result + i ;
CISS
1 2 3 4 5 6 7 8 9 10 11 12
IF value < 0 THEN value := - value ; WHILE ( i < value ) AND ( result <= maxint ) DO OD; IF result <= maxint THEN OUTPUT ( result ) ELSE OUTPUT ( too large ) END. i := i + 1 ; result := result + i ;
6-7
11
10
12
CISS
CISS
value < 0 no
yes
value:= -value;
output(too large);
CISS
Strongest white-box criterion Usually impossible: infinitely many paths ( in case of loops ) So: not a realistic option But note : enormous reduction w.r.t. all possible test cases
( each sequence of statements executed for only one value )
CISS
value < 0 no
yes
value:= -value;
Path:
start
output(too large);
CISS
Example:
IF b THEN s1 ELSE s2 IF b THEN s1; s2 CASE x OF
1 : . 2 : . 3 : .
CISS
value < 0 no
yes
value:= -value;
output(too large);
CISS
value < 0 no
yes
value:= -value;
maxint -1 -1 -1 10 10
value -1 -1 -1 3 3
But:
No green path !
output(too large);
CISS
value < 0 no
yes
value:= -value;
output(too large);
CISS
Example:
decision ( i < value ) AND (result <= maxint )
consists of two conditions : ( i < value ) AND (result <= maxint ) test cases should be designed such that each gets value true and false at least once
CISS
value < 0 no
yes
value:= -value;
1 0 false true gives condition coverage for all conditions But it does not preserve decision coverage
always take care that condition coverage preserves decision coverage : decision / condition coverage
output(too large);
CISS
Implies decision-, condition-, decision/condition coverage But : exponential blow-up Again : some combinations may be infeasible
CISS
Zero iterations One iteration Two iterations Typical number of iterations n-1, n, and n+1 iterations (n maximum number of allowable iterations)
Single loop strategy often intractable Select minimum values for outer loop(s) Treat inner loop as a single loop Work outwards and choose typical values for inner loops Concatenated loops: Treat as single, if independent Treat as nested, if dependent
CISS
value < 0 no
maxint
value
15 0
i:=i+1; result:=result+i; (i<value) and (result<=maxint) no yes
15 1 15 2 15 3 6 4 15 5
output(too large);
CISS
CISS
Dm,v
IF value < 0 THEN value := - value ; WHILE ( i < value ) AND ( result <= maxint ) DO OD; IF result <= maxint THEN OUTPUT ( result ) ELSE OUTPUT ( too large ) Ui,v,r,m i := i + 1 ; result := result + i ;
Dr,i Uv Uv;Dv
4
Ur,i;Dr,i
5 6-7
10
12
CISS
White-Box : Overview
statement coverage condition coverage decision/ condition coverage multiplecondition coverage path coverage decision (branch) coverage
CISS
White-Box : Overview
statement coverage all defs coverage all uses coverage decision (branch) coverage
CISS
Random testing:
Basic idea: run the program with arbitrary inputs Inherent problems: How to define the oracle for arbitrary
inputs and how to decide to stop? Advantage: The program structure can be ignored
CISS
100 34 84
CISS
Overview
Black-box testing (or functional testing):
Equivalence partitioning Boundary value analysis Cause-effect graphing Behavioural testing Random testing Error guessing etc Domain analysis
How to use black-box and white-box testing in combination Basics : heuristics and experience
CISS
input events
x CISS
Leads to a logical partitioning of the input/output domain into Leads to a flow-graph-like model, which enables application of
techniques from the white-box world (on the black-box model)
CISS
CISS
Define one / couple of test cases for each class Test cases that cover valid eq. classes Test cases that cover at most one invalid eq. class
CISS
Test cases :
x = -10, x = XYZ, x = 100 x=x = 10 20
CISS
CISS
CISS
Formally:
Given integer inputs maxint and value compute result :
|value|
result =
k
K=0
CISS
Test Cases :
Valid
Invalid
10 -10 10 30 10 9.1E4
CISS
CISS
Test cases :
class x < 0, arbitrary value: class x >= 0, arbitrary value classes x < 0, x >= 0, on boundary : classes x < 0, x >= 0, below and above: x = -10 x = 100 x=0 x = -1, x = 1
CISS
CISS
result =
k
K=0
CISS
Test Cases :
maxint value result maxint value result
55 54 56 0
10 10 10 0
55 error 55 0
0 -1 1 .
0 1 1 .
CISS
Make Boolean Graph linking causes and effects Annotate impossible combinations of causes and effects Develop decision table from graph with in each column
a particular combination of inputs and outputs
CISS
and
error
Effects outputs
k error
1 0
1 0
0 1
0 1
CISS
Combinatorial explosion of number of possible combinations Some heuristics to reduce this combinatorial explosion Starting point is effects (outputs) then working backwards light-weight formal methods:
transformation into semi-formal Boolean graph
CISS
CISS
CISS
CISS
CISS
CISS
CISS
Black-box: random/stochastic
Basic idea: Drive the system through typical scenarios, extreme
scenarios, and rare scenarios in a random way. Motivation: Increase the chance of hitting system faults. Application areas: Systems that run forever in some nondetermistic way, e.g. control
Examples:
Random mouse clicking/typing towards a GUI. Typical browser-user behaviour: (click;read;)* with a typical random
distribution of waiting time Random walk through a specification state model while testing
CISS
CISS
CISS
Risk Analysis
CISS
CISS
CISS
Use a coverage tool Design additional white-box test cases for not covered code
CISS
CISS