# whiteboxtest

Document Sample

```					Whitebox Testing

CS2335
Spring 2007
Whitebox Testing
AKA Structural, Basis Path, Glassbox Test
Normally used only 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
Coverage 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…
Motivation

What happens when good software goes bad?

AT&T 4ESS switch meltdown
Unit Module Specification
Invoices are calculated using the following
algorithm:
Item X sells for \$5 and Item Y sells for \$10
Invoice Total >=\$200 get 5% discount
Invoice Total >=\$1000 get 10% discount
Invoices that order more than 30 X items
get a 5% discount
Example Program                                               if
public decimal invoice (decimal x, decimal y) {                       s>1000
decimal d1, d2, s;                 if
x>30

if (x<=30) d2=1.0M;                                 d1=.95

else d2=0.95M;                    d2=1     d2=.95

s=5 * x + 10 * y;                                                 d1=.90

if (s<=200) d1=1.0M;
else if (s<=1000) d1 = 0.95M;
else d1 = 0.90M;                    s>200
return (s*d1*d2);                   if
}
return

d1=1
Statement Coverage
if
s>1000
x>30
if
d1=.95

d2=1      d2=.95

d1=.90

Test Case    Expected Output

s>200                              X=5 Y=5      75
if
return                X=31 Y=10    229.5

X=30 Y=100   977.5
d1=1
Branch Coverage
if
s>1000
x>30
if
d1=.95

d2=1      d2=.95

d1=.90

s>200
Test Case    Expected Output
if
return                X=5 Y=5      75

X=31 Y=10    229.5
d1=1
X=30 Y=100   977.5
Path Coverage                                      With loops impossible
if
x>30
s>1000
6 Test Cases
if
d1=.95

d2=1      d2=.95

d1=.90

s>200
if
return

d1=1
Data Flow Testing
All du paths
All u
All c / some p
All p / some c
All d
All p
Some 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
Data FlowTesting
x, y, d1, d2, s
dddd                                      p   if
1

s>1000
x>30
p       if                   d
d       6

d           2            3                          d

7

d        4     cc

s>200
p    if
8        c cc

d
5
Exercise 1
void handleCommandModeKeypress(char c) {
if (c==‘:’) startMulticharCommand( c );
else if (c>=‘0’ && c <=‘9’) doRepeatedCommand( c );
else switch(c) {
case ‘x’:
doSingleCharDelete( );
break;
case ‘d’:
doLineDelete( );               Generate Test Cases for:
break;                          Statement
}                                  Branch
}                                    Paths
Solution
C=‘:’
if
C>=‘0’
Statement                                 if
c=‘:’
c=‘x’                                                           if
c=‘d’
c=‘1’                                                                C<=‘9’

switch
Branch                                         C=‘d’
C=‘x’
c=‘ ‘

Path
c=‘e’
Dataflow Solution
d
No new test paths??
if
p                p    if

c                                       p
if

p
switch
c
Dataflow Anomolies
dd   harmless, but suspicious
kk   possible bug
kd   normal
ku   bug
-k   possible bug
-u   bug
Strength of Coverage
All Paths

All du Paths

All u

All c some p                  All p some c

All d         All p

Branch

Statement
How effective?
Strategy         Mean Cases   Bugs Found
Random Testing     100            79.5
Branch Testing      34             85.5
All Uses             84            90.0
Exercise 2                              d d

while
p                  c>=0
void doRepeatedCommand(char c) {
char buffer[256];                                        p
while
int index=0;                                                               c<=9
int value = 0;                                                 c,d
while (c>=0 && c<=9) {                    c                    c,d
buffer[index++]=c;
c=getch();                          dpc                    index<value
for
}
buffer[index]=‘\0’;
value=atoi(buffer);
for (index=0;index<value;index++) {   c

handleSingleCommand( c );
}
}
Next Time
Specification-Based / Blackbox Testing

DEFECTUS
ELIMINATO

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 3 posted: 6/3/2011 language: English pages: 20
About if any file u wil find copyright contact me it will be remove in 3 to 4 buisnees days. add me on sanjaydudeja007@gmail.com or visit http://www.ohotech.com/