Professional Documents
Culture Documents
White Box Testing
White Box Testing
muazzam.maqsood@cuiatk.edu.pk
Presentation Outline
- White Box Testing
- Unit Testing
- Cyclomatic Complexity
- Graph matrices
- Condition Testing
- Loop Testing
- DC Path
▪ White box testing (a.k.a. clear box testing, glass box testing, transparent
box testing, translucent box testing or structural testing)
▪ The tests written based on the white box testing strategy incorporate
coverage of the code written, branches, paths, statements and internal
logic of the code etc.
▪ In order to implement white box testing, the tester has to deal with the
code and hence is needed to possess knowledge of coding and logic i.e.
internal working of the code.
▪ In the language of V&V, White box testing is often used for verification
(Are we building the software right?)
White Box Testing
▪ Using White box testing methods, the software engineer can
derive test cases that:
1. Statement Coverage
2. Segment Coverage
3. Branch Coverage
7. Loop Testing
Code Coverage
▪It is a form of testing that looks at the code directly and as such comes
under the heading of white box testing.
▪ Statement Coverage:
▪ Segment coverage:
▪ Branch Coverage:
When there are multiple conditions, you must test not only each
direction but also each possible combinations of conditions, which is usually
done by using a "Truth Table".
▪ Loop Testing:
This strategy relate to testing single loops, concatenated loops,
and nested loops. Loops are fairly simple to test unless dependencies exist
among the loop or b/w a loop and the code it contains.
▪In flow graph each circle (a flow graph node) represents one or more
procedural statements.
▪A sequence of process boxes and a decision diamond can map into a single
node.
▪The arrows on the flow graph called edges or links represents flow of
control.
▪An edge must terminate at a node even if the node does not represent any
procedural statements.
Decision
Point
▪A decision is a program point at
which the control can diverge.
Junction
Point
C
If C Then S1 else S2;
Sequential statement block
S1 S2
C Case C of
C
L1: S1; If C Then S1;
S1 Sn L2: S2;
…
Kn: Sn; S1
end;
C I =1
While C do S; For loop:
F for I = 1 to n do S;
T S
S
yes
I <=n
no
S1 Do loop:
do S1 until C;
F
C
T
i=1; 2
1 total.input = total.valid = 0;
Sum=0;
Do while value[i]<>-999 and total.input <= 100 3
4 increment total.input by 1;
IF value[i] >= minimum and value[i] <=maximum 6
5 THEN increment total.valid by 1;
7 sum = sum + value[I];
8 ENDIF
increment i by 1;
9 Enddo
IF value[i] >0 10
ENDIF 13
Flow Graph
1
10
3
12 11 4
13
5
7
8
9
Cyclomatic Complexity
▪When this metric is used in the context of the basis path testing, the value
computed for cyclomatic complexity defines the number of independent paths
in the basis set of a program.
1 node
No. of regions = 4
(considering the universal region)
edge 2 3
No. of edges = 9
4 No. of nodes = 7
1
a
e b d
5
4
f
c
g
2 FLOW GRAPH
▪ The link weight 1(a connection exists) and 0(a connection does not
exists).
NODE 1 2 3 4 5
1 a
2
3 d b
4 c f
5 g e
Graph Matrix
NODE 1 2 3 4 5
1 1
2
3 1 1
4 1 1
5 1 1
Connection Matrix
For example,
path 1: 1-2-4-5-6-7
path 2: 1-2-4-7
path 3: 1-2-3-2-4-5-6-7
path 4: 1-2-4-5-6-5-6-7
Step 4: Prepare test cases that will force execution of each path in the
basis set.
▪ For a compound condition Com, the true and false branches of Com and
every simple condition in Com need to be executed at least once.
A B C A&B or C
❑ Are all indices used to access an array inside the array's dimensions?
1. Simple loops
2. Concatenated loops
3. Nested loops
❑ defined,
❑ used in a predicate,
❑ used in a calculation, and
❑ killed.
❑ defs at 1,4
❑ use at 6
▪ 1,2,3,5,6 is a definition-
clear path from 1 to 6
❑ x is not re-assigned
between 1 and 6
▪ 1,2,4,5,6 is not a
definition-clear path from
1 to 6