Ch4 ControlFlowTesting
Ch4 ControlFlowTesting
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1
2
• Basic Idea
© Naik & Tripathy
•
• Summary
Two kinds of basic program statements:
3
•
– Assignment statements (Ex. x = 2*y; )
© Naik & Tripathy
Figure 4.1: The process of generating test input data for control flow testing.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 4
Inputs to the test generation process
5
•
– Source code
© Naik & Tripathy
– Compilers are modified to produce CFGs. (You Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing)
can draw one by hand.)
• Selection of paths
– Enough entry/exit paths are selected to satisfy
path selection criteria.
• Generation of test input data
– Two kinds of paths
• Executable path: There exists input so that
the path is executed.
• Infeasible path: There is no input to execute
the path.
– Solve the path conditions to produce test input
for each path.
Control Flow Graph
•
Figure 4.2: Symbols in a control flow graph
Symbols in a CFG
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 6
Control Flow Graph
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 7
• Example code: ReturnAverage()
8
public static double ReturnAverage(int value[], int AS, int MIN, int MAX){
/* Function: ReturnAverage Computes the average of all those numbers in
© Naik & Tripathy
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 9
10
1-2-3(F)-10(F)-11-13
SCPath2
Branch coverage criterion
11
•
– A branch is an outgoing edge from a node in a
© Naik & Tripathy
CFG.
• A condition node has two outgoing branches
– corresponding to the True and False values
of the condition.
– Covering a branch means executing a path that
contains the branch. Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing)
– 100% branch coverage means selecting a set of
Path Selection Criteria
Figure 4.8: The dotted arrows represent the branches not covered
by the statement covering in Table 4.4.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 12
13 © Naik & Tripathy
1-2-3(T)-4(T)-5-6(T)-7(T)-8-9-3(F)-10(T)-12-13
BCPath 1
BCPath 2
BCPath 3
BCPath 4
BCPath 5
Predicate coverage criterion
14
•
– If all possible combinations of truth values of the
© Naik & Tripathy
Figure 4.9: Partial control flow graph with (a) OR operation and (b)
AND operation.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 15
Having identified a path, a key question is
16
•
how to make the path execute, if possible.
© Naik & Tripathy
– Predicate interpretation
– Path predicate expression
– Generating test input from path predicate
expression
Input vector
17
•
– An input vector is a collection of all data entities
© Naik & Tripathy
programming)
• Network connections
• Timers
– Example: An input vector for openfiles() consists
of individual presence or absence of the files
“files1,” “file2,” and “file3.”
– Example: The input vector of ReturnAverega()
shown in Figure 4.6 is <value[], AS, MIN,
MAX>.
Predicate
18
•
– A predicate is a logical function evaluated at a
© Naik & Tripathy
decision point.
– Example: ti < AS is a predicate in node 3 of
Figure 4.7.
– Example: The construct OB is a predicate in node
5 in Figure 4.9.
• Path predicate
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing)
– A path predicate is the set of predicates
Generating Test Input
•
– A path predicate may contain local variables.
© Naik & Tripathy
of
– symbolically substituting operations along a
path in order to express the predicate solely in
terms of the input vector and a constant
vector.
– A predicate may have different interpretations
depending on how control reaches the predicate.
Path predicate expression
20
•
– An interpreted path predicate is called a path
© Naik & Tripathy
predicate expression.
– A path predicate expression has the following
attributes.
• It is void of local variables.
• It is a set of constraints in terms of the input
vector, and, maybe, constants.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing)
• Path forcing inputs can be generated by
Generating Test Input
•
– An example of infeasible path
© Naik & Tripathy
•
expression
© Naik & Tripathy
•
of paths.
© Naik & Tripathy
•
program execution.
© Naik & Tripathy