Professional Documents
Culture Documents
White-Box Testing
Uses the control structure part of component-level design
to derive the test cases
These 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
Exercise internal data structures to ensure their validity
“Bugs lurk in corners and congregate at boundaries” BACK
White-Box Testing
There exist several popular white-box testing methodologies:
control flow graph:
Statement coverage
Branch coverage
Path coverage
mutation testing:
BACK
Control flow graph (CFG)
A control flow graph (CFG) describes:
the sequence in which different instructions of a
program get executed.
the way control flows through the program.
Steps to draw Control flow graph
Number all the statements of a program.
Numbered statements:
represent nodes of the control flow graph.
An edge from one node to another node exists:
if execution of the statement representing the first node
can result in transfer of control to the other node.
Example
int f1(int x,int y){
1. while (x != y){
2. if (x>y) then
3. x=x-y;
4. else y=y-x;
5. }
6. return x; }
1
2
3 4
5
6
0 0
R4
1 1
F
2 L 2
O
3 W R3
3
6 4 G 6 4
R R2
7 8 5 A
7 R1 8 5
P
9 H
9
11 13
10 11 10
Independent Program Paths
Defined as a path through the program from the start node
until the end node that introduces at least one new set of
processing statements
Must move along at least one edge that has not been
traversed before by a previous path
Basis set for flow graph on previous slide
Path 1: 0-1-11
Path 2: 0-1-2-3-4-5-10-1-11
Path 3: 0-1-2-3-6-8-9-10-1-11
Path 4: 0-1-2-3-6-7-9-10-1-11
The number of paths in the basis set is determined by the
cyclomatic complexity
Cyclomatic Complexity
Provides a quantitative measure of the logical complexity of a program
Defines the number of independent paths in the basis set and the number of
tests that must be conducted to ensure all statements have been executed at
least once
Can be computed three ways
The number of regions
V(G) = E–N+2, where E is the number of edges and N is the number of
nodes in graph G
V(G) = P+1,where P is the number of predicate nodes
Results in the following equations for the example flow graph
Number of regions = 4
V(G) = 14 edges – 12 nodes + 2 = 4
V(G) = 3 predicate nodes + 1 = 4
Deriving the Basis Set and Test Cases
Using the design or code as a foundation, draw a
corresponding flow graph
Determine the cyclomatic complexity of the resultant flow
graph
Determine a basis set of linearly independent paths
Prepare test cases that will force execution of each path in
the basis set
Data Flow Testing
The techniques discussed so far have all been based on "control
flow"
we can also design test cases based on "data flow“(how data flows
through the code)
Some statements "define" a variable’s value (“variable definition”)
Variable declarations with initial values
Assignments
Incoming parameter values
Some statements "use" variable’s value (“variable use”)
Expressions on right side of assignment
Boolean condition expressions
Loop Testing
A white-box testing technique that focuses exclusively on
the validity of loop constructs
Four different classes of loops exist
Simple loops
Nested loops
Concatenated loops
Unstructured loops
Testing occurs by varying the loop boundary values
Examples:
for (i = 0; i < MAX_INDEX; i++)
while (currentTemp >= MINIMUM_TEMPERATURE)
Testing of Simple Loops
Skip the loop entirely
Only one pass through the loop
Two passes through the loop
m passes through the loop, where m < n
n –1, n, n + 1 passes through the loop
BACK
Mutation Testing
The software is first tested:
using an initial testing method based on white-box
strategies.
After the initial testing is complete,
mutation testing is taken up.
The idea behind mutation testing:
make a few arbitrary small changes to a program at a
time.
Mutation Testing
Each time the program is changed,
it is called a mutated program
the change is called a mutant.
A mutated program:
tested against the full test suite of the program.
If there exists at least one test case in the test suite for which:
a mutant gives an incorrect result, then the mutant is said
to be dead.
If a mutant remains alive:
even after all test cases have been exhausted, the test
suite is enhanced to kill the mutant.
The process of generation and killing of mutants:
can be automated by predefining a set of primitive changes
that can be applied to the program.
The primitive changes can be:
altering an arithmetic operator,
changing the value of a constant,
changing a data type, etc.
BACK
Advantages Of White Box Testing
BACK
Disadvantages of white box testing
Developers often test with the intent to prove that the code works
rather than proving that it doesn't work
Developers tend to skip the more sophisticated types of white box
tests (e.g., condition testing, data flow testing, loop testing, etc.),
relying mostly on code coverage
And developers also tend to overestimate the level of code
coverage
White box testing focuses on testing the code that's there. If
something is missing, white box testing might not help you.
There are many kinds of errors that white box testing won't find
Timing and concurrency bugs
Volume and load limitations
Efficiency problems
Usability problems
BACK