Title: Whitebox Testing
1Whitebox Testing
2Whitebox Testing
- AKA Structural, Basis Path Test
- Normally used at unit level
- Assumes errors at unit level are in the control
structure or data path - Generates test cases to test control paths
through the code - Criteria includes Control-Flow and Data-Flow
based coverage
3Coverage Criteria
- Control Flow based
- Statement Coverage (All nodes)
- Branch (or Decision) Coverage (All edges)
- All Paths
- Data Flow based
- All DU paths
- All C uses
- All Defs
- Etc
4Motivation
What happens when good software goes bad? ATT
4ESS switch meltdown
5Unit Module Specification
Invoices are calculated using the following
algorithm Item X sells for 5 and Item Y sells
for 10 Invoice Total gt200 get 5 discount
Invoice Total gt1000 get 10 discount
Invoices that order more than 30 X items
get a 5 discount
6Example Program
int invoice (int x, int y) int d1, d2, s
if (xlt30) d2100 else d290 s5x 10
y if (slt200) d1100 else if (slt1000) d1
95 else d1 80 return
(sd1d2/10000)
7Statement Coverage
8Branch Coverage
9Path Coverage
With loops impossible
6 Test Cases
10Data Flow Testing
- All du paths
- All u
- All c / some p
- All p / some c
- All d
- All p
11Some Definitions
- Definition-Use (sub)path wrt variable v such
that DEF(v,m) and USE(v,n) and m, n are the
initial and final nodes of the (sub)path. - Definition-Clear (sub)path wrt variable v such
that DEF(v,m) and USE(v,n) and not other node in
the subpath is a DEF node for v
12Data FlowTesting
x, y, d1, d2, s
if
p
d d d d
1
sgt1000
xgt30
if
p
d
6
d
2
3
d
d
7
4
c c
d
sgt200
if
p
8
c c c
d
5
13Exercise 1
void handleCommandModeKeypress(char c) if
(c) startMulticharCommand( c ) else if
(cgt0 c lt9) doRepeatedCommand( c )
else switch(c) case x
doSingleCharDelete( ) break case
d doLineDelete( ) break
Generate Test Cases for Statement Branch
Paths
14Solution
C
Cgt0
Clt9
Cd
Cx
15Dataflow Solution
d
No new test paths??
p
p
p
c
p
c
16Dataflow Anomolies
- dd harmless, but suspicious
- kk possible bug
- kd normal
- ku bug
- -k possible bug
- -u bug
17Strength of Coverage
All Paths
All du Paths
All u
All c some p
All p some c
All d
All p
Branch
Statement
18How effective?
Strategy Mean Cases Bugs Found Random Testing
100
79.5 Branch Testing 34
85.5 All Uses
84
90.0
19Exercise 2
void doRepeatedCommand(char c) char
buffer256 int index0 int value 0
while (cgt0 clt9) bufferindexc
cgetch() bufferindex\0
valueatoi(buffer) for (index0indexltvaluein
dex) handleSingleCommand( c )
20Next Time
Specification-Based / Blackbox Testing
DEFECTUS ELIMINATO