Sei sulla pagina 1di 24

WHITE BOX TESTING

ANUJA ARORA CSE / IT JIITU, NOIDA

Structural (White-box) testing


Sometimes called white-box testing. Derivation of test cases according to program structure. Knowledge of the program is used to identify additional test cases. Sometimes called White Box technique. Objective is to exercise all program statements (not all path combinations).

How to drive test cases


Guarantee that all independent paths within a module have been exercised at least once. Exercise all logical decisions on their true and false sides. Execute all loops at their boundaries and within their operational bounds. Execute internal data structure to ensure their validity

Structural testing

Flow chart vs flow graph


1

1 2 3 6 7 8 6

2,3

4,5 8

4
5

7 9

10 11

Data flow testing


Data flow based criteria, a definition-use graph (def / use graph ). First constructed from the control flow graph. A statement in a node in the flow graph representing a block of code has variable occurrence in it. Variable occurrence is out of these 3 types : 1. def :- definition of variable. The variable at left hand side of an assignment statement. 2. c-use :- computational use of variable .all variables at right hand side have a c-use occurrence. In r/w statement all variable occurrence are of this type. 3. p-use :- predicate use. variables whose value are used for computing the value of the predicate, used for transfer of control.

Data flow based testing (example)


1. scanf ( x , y ) ; if ( y < 0 ) 2. pow = 0 y; 3.else pow = y; 4.z = 1. 0; 5.while ( pow != 0) 6.{ z = z * x ; pow = pow 1;} 7.if ( y < 0 ) 8.z = 1. 0 / z ; 9.printf ( z );

Def / use graph :1


y

def = { x , y } c-use =
y

def = { pow } c-use ={ y }

2 4

def = { pow } C-use = { y }

def = { z } c-use =

5
def = { z , pow } c-use = { x , z , pow }

def = c-use = pow

pow
y

def = c-use =
y

def = { z } c-use = { z }

def = c-use = { z }

Data flow based testing (example)


(Node,var) (1,x) (1,y) (2,pow) (3,pow) (4,z) (6,z) (6,pow) (8,z) dcu {6} {2,3} {6} {6} {6,8,9} {6,8,9} {6} {9} dpu {(1,2),(1,3),(7,8),(7,9)} {(5,6),(5,7)} {(5,6),(5,7)} {(5,6),(5,7)}

Data flow based testing (example)


dcu :- suppose a variable x is in def ( i ) of a node i. Then dcu ( x,i)
is the set of nodes, such that each node has x in its c-use. x def ( i ) and there is def clear path from i to j. i.e. dcu( x, i )represent all those edges in which the global c-use of x uses the value assigned by the def of x in i. of edges such that each edges has x in its p-use x def ( i ) and there is def clear path from i to ( j, k ) i.e. dpu ( x, i) represents all those edges in which the p-use of x uses the value assigned by the def of x in i.

dpu :- dpu( x , i ) is the set

def clear:- def clear path from i to

j mean a path from node i to j w.r.t. a variable x. similarly , there is def clear path from i to ( j, k )

Path testing
The objective of path testing is to ensure that the set of test cases is such that each path through the program is executed at least once. The starting point for path testing is a program flow graph that shows nodes representing program decisions and arcs representing the flow of control. Statements with conditions are therefore nodes in the flow graph.

Driving Test cases


Step:-1 Using the design or code as a foundation, draw a corresponding flow graph . Step:-2 Determine the cyclomatic complexity of the resultant flow graph . Step:-3 Determine a basic set of linearly independent paths . Step:-4 prepare test cases that will focus execution of each path in the basis set .

1 2 3 4 10 11 13 12 8 9 FLOW GRAPH FOR PROCEDURE AVERAGE 5 6 7

example

PROCEDURE average; *This procedure computes the avearage of 100 or fewer number that lie between bounding values; It also compute the sum and total number valid INTERFACE RETURNS average,total.input,total.valid; INTERFACE ACCEPT values,minimum,maximum; TYPE values[1:100] IS SCALAR ARRAY; TYPE i IS INTEGER; i = 1; total.input = total.valid = 0; Sum = 0; DO WHILE value [i] <>-999 AND total.input <100

1 4 5

2 3 6

increment total.input by 1 IF value [i] > = minimum AND value [i] < = maximum THEN increment total.valid by 1; sum= s sum + value [i] ELSE skip ENDIF increment i by 1; END DO IF total.valid > 0

8 9

10 11 12

THEN average = sum / total.valid ELSE average = -999;

13 ENDIF

Cyclomatic complexity
It is a software metric that provides a quantitative measure of the logical complexity of a program The value computed for cyclomatic complexity Defines the number of independent path in the basic set of a program Provide us the number of upper bound for the number of tests that must be conducted to ensure that all statement have been executed at least once.

Cyclomatic complexity (cont.)


CC has a foundation in graph theory and is computed in one of the three ways: 1. The number of regions corresponds to the cyclomatic complexity. 2. Cyclomatic complexity, V(G) ,for a flow graph ,G, is defined as V(G)=E N + 2 E - No of flow graph edges 3. Also defined as V(G) = P + 1 P number of predicate nodes contained in flow graph G . N - No of flow graph node

Cyclomatic complexity (cont.)


Predicate nodes:- That contains a condition is called a predicate node and characterized by two or more edges emanating from it. Regions:- Area bounded by edges and nodes . V(G) =6 regions V(G)=17(edges)-13(nodes) + 2 = 6 V(G)=5(predicate nodes) + 1 11
Note:- Predicate nodes by Blue

1 2 3 4

10
R1, R2

5 12 8
R5,R6 R4

6
R3

13

Independent paths
path 1 : path 2 : path 3 : path 4 : path 5 : path 6 : path 7 : 1-2-10-11-13 1-2-10-12-13 1-2-3-10-11-13 1-2-3-10-12-13 1-2-3-4-5-8-9-2-.. 1-2-3-4-5-6-8-9-2- 1-2-3-4-5-6-7-8-9-2-

Binary search flow graph

Independent paths
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14 1, 2, 3, 4, 5, 14 1, 2, 3, 4, 5, 6, 7, 11, 12, 5, 1, 2, 3, 4, 6, 7, 2, 11, 13, 5, Test cases should be derived so that all of these paths are executed A dynamic program analyser may be used to check that paths have been executed

Graph Matrices
Tabular representation of a flow graph.
1
a e f g
1 2 1 2 3 4 5

a d c g e b f

3
b

4
2

d c

3 4 5

Adding link weight to each matrix entry, most powerful tool for evaluating program control structure during testing.

Graph Matrices(cont.)
In simplest form link weight is 1(connection exist) or 0(connection not exist) Link weight can be assigned other:
The probability that a link (edge) will be executed Processing time expanded during traversal of a link The memory required during traversal of a link . The resource required during traversal of a link .

Key points
Testing can show the presence of faults in a system; it cannot prove there are no remaining faults. Component developers are responsible for component testing; system testing is the responsibility of a separate team. Integration testing is testing increments of the pow system; release testing involves testing a system to be released to a customer. Use experience and guidelines to design test cases in defect testing.

Key points
Interface testing is designed to discover defects in the interfaces of composite components. Equivalence partitioning is a way of discovering test cases - all cases in a partition should behave in the same way. Structural analysis relies on analysing a program and deriving tests from this analysis.

Potrebbero piacerti anche