Chapter 4 Part I Structural (White Box) Testing
Chapter 4 Part I Structural (White Box) Testing
SEng5441
KIoT
Department of Software Engineering
1
White Box testing
White-box testing(also called clear box testing, glass box testing, transparent box
testing, or structural testing)is a method of testing software that tests internal
structures or workings of an application [the tester has access to the internal data
structures and algorithms including the code that implement these.]
White box testing methods are especially useful for revealing design and code-
based control, logic and sequence defects, initialization defects, and data flow
defects.
2
Control flow refers to flow of control from one instruction to another
The main idea in control flow testing is to appropriately select a few paths
in a program unit and observe whether or not the selected paths produce
3
the expected outcome.
Outline of Control Flow Testing
4
Figure 1: The process of generating test input data for control flow testing.
Basic Idea
• Program path
– A program path is a sequence of statements from entry to exit.
– Executing a path requires invoking the program unit with the right/correct test input.
• Selection of paths
– Enough entry/exit paths are selected to satisfy path selection criteria.
– Path 2: 1-2-3(F)-10(F)-11-13
– Path 3: 1-2-3(T)-4(T)-5-6(T)-
7(T)-8-9-3(F)-10(T)-12-13
– Path 4: 1-2-3(T)-4(T)-5-6(T)-7(T)-
8-9-3(T)-4(T)-5-6(T)-7(T)-8-9-3(F)
-10(T)-12-13
8
Path Selection Criteria
1. All-path coverage criterion: Select all the paths in the program unit .
Advantage:
- it is desirable since it can detect error, except those due to missing path errors.
Disadvantages
– A program may contain a large number of paths, or even an infinite number of paths . It’s difficult
– Producing all the inputs that exercise all the program paths is difficult process.
10
Path Selection Criteria…
2. Statement coverage criterion
– Statement coverage means executing individual program statements (nodes) and observing the output.
– 100% statement coverage means all the statements have been executed at least once.
• Cover all assignment statements (i=0, ti=0,tv=0, sum=0) represented by node 2 in CFG
• Cover all conditional statements, ((ti < AS && value[i] != -999) represented by nodes 3,4, 6, 7 and 10
in CFG.
– Less than 100% statement coverage is unacceptable.
– Since a single entry–exit path includes many nodes, we need to select just a few paths to cover all the nodes of a CFG.
11
Path Selection Criteria…
Finger 3 12
Path Selection Criteria…
13
Path Selection Criteria…
• A condition node has two outgoing branches – corresponding to the True and False values
of the condition.
• All the rectangle nodes have at most one outgoing branch (edge)
– Complete(100%) branch coverage means selecting enough number of paths such that
every condition evaluates to true at least once and to false at least once.
14
Path Selection Criteria
–Example of Paths selected based on Branch coverage
criterion and CFG
The code highlighted in yellow will be The code highlighted in yellow will
executed. Here the “No” outcome of the be executed. Here the “Yes”
Branch/decision If (a>5) is checked. outcome of the Branch/decision If
(a>5) is checked.
Branch Coverage = 50%
Branch Coverage = 50%
17
Generating Test Input
1-Input vector
– An input vector is a collection of all data entities read by the routine whose values must be
fixed prior to entering the routine.
– Members of an input vector can be as follows.
• Input arguments to the routine
• Global variables and constants
• Files
• Contents of registers (in Assembly language programming)
• Network connections
• Timers
– Example: The input vector of ReturnAverega() shown in Figure 2 is <value[], AS, MIN,
MAX>.
18
Generating Test Input
2- Predicate
– A predicate is a logical function evaluated at a decision point.
– Example of a predicate: the construct ti < AS is a predicate in node 3 of Figure 2.
– Example of a predicate: Value[i]<=Max is a predicate in node7 of Figure 2.
3- Path predicate
– A path predicate is the set of predicates associated with a path.
– The path in Figure 2 indicates that nodes 3, 4, 6, 7, and 10 are decision nodes
– An example path from Fig. 2:
1-2-3(T)-4(T)-5-6(T)-7(T)-8-9-3(F)-10(T)-12-13.
– The example of path predicate for the path shown in Figure 2.
ti < AS ≡ True
value[i] != -999 ≡ True
value[i] >= MIN ≡ True
value[i] <= MAX ≡ True
ti < AS ≡ False
tv > 0 ≡True
19
Generating Test Input
4-Predicate interpretation
– The path predicate shown in Figure 2 from the previous slide is composed of elements of
the input vector < value[], AS, MIN, MAX >, a vector of local variables < i, ti, tv >, and
the constant -999.
– Local variables play no role in selecting inputs that force a path to execute.
– Local variables can be eliminated by a process called symbolic execution.
– Predicate interpretation is defined as the process of
– symbolically substituting operations along a path in order to express the predicate only in terms of the
input vector and a constant vector.
– A predicate may have different interpretations depending on how control reaches the predicate.
21
Generating Test Input…
Note: The bold entries in column 1 denote TABLE 3: Interpretation of Path Predicate of Path (1-2-3(T)-
4(T)-5-6(T)-7(T)-8-9-3(F)-10(T)-12-13.) 22
interpreted predicates.
Cont.…
– example of Path predicate expression for the path shown in the previous slide.
0 < AS ≡ True …… (1)
value[0] != -999 ≡ True …… (2)
value[0] >= MIN ≡ True …… (3)
value[0] <= MAX ≡ True …… (4)
1 < AS ≡ False …… (5)
1>0 ≡ True …… (6)
– An example of infeasible path from Figure 2.
1-2-3(T)-4(F)-10(T)-12-13
24
Generating Test Input