CH 4 part II
CH 4 part II
Department of
Software
engineering 4th
Year
Software testing and quality
assurance
Presented by: Demeke M.
MEKDELA AMBA U.
Chapter 4 part II
Chapter
four
White Box
Data Testing
flow
te sti
Data flow testing 3
Introduction
o A program unit such as a function, accepts input values, performs computations while
assigning new values to local and global variables, and, finally, produces output
values.
o Therefore, one can imagine a kind of “flow” of data values between variables along a
path of program execution
o A data value computed in a certain step of program execution is expected to be used in a
later step.
Example: Obtain a file pointer ……. use it later.
• If the later use is never verified, we do not know if the earlier assignment is acceptable.
Data flow testing 4
Data flow testing
o Data flow testing is one form of structural testing or white box testing
approach.
o Data flow testing is the flow of data in a program/instruction.
o It is a method that is used to aims to identify and eliminate potential
anomalies that could disrupt the flow of data, leading to program
malfunctions or erroneous outputs.
Data flow testing 5
Cont.
o … issues such as
By analyzing control flow graphs, data flow testing aims to identify
unused variables or incorrect definitions, ensuring proper handling of data within
the code.
o We focus on the points at which
• Variable received value
• At which these values are used
Data flow testing 6
Cont.
o Variable occur in statement as
…
Definition – def
• Either initialization, input or assignment
• E.g. int x, x = 3, input x
Computational usage – c-use
• Variable are use in write statement
• E.g. y = x+9; (in this case x is used)
Predicate – p-use
• Variable are used in a decision-making context, such as in a condition or a
predicate expression (e.g., in an if statement, while loop, or for loop).
• E.g. if(x != 0)
Data flow testing 7
x = f1(y);
x = f2(z);
o Type 2: Undefined but referenced
• A second form of data flow anomaly is to use an undefined
variable in a computation.
• Example: int x, y;
x = x – y – w; /* where the variable w has not been initialized/defined by the
programmer. */
Data flow testing 1
Cont. 1
flow
graph
public static double ReturnAverage(int value[], int AS, int MIN,
int MAX) {
int i, ti, tv, sum; double av;
i = 0; ti = 0; tv = 0; sum = 0;
while (ti < AS && value[i] != -999) { ti++;
if (value[i] >= MIN && value[i] <=
MAX)
{
tv++;
sum = sum + value[i];
Data flow testing 1
Data flow graph 5
Def() and c-use() the above Predicates and p-use() the above
DFG DFG
Data flow testing 1
6
Def clear
o path
Definition clear path: A path (n – n – … n 1 m – m), m ≥ 0, is called a definition
clear path (def-clear path) with respect to variable x
• from node n to node m, and
• from node n to edge (m, k),
A B
Which satisfy def clear?
Data flow testing 1
8
Data flow testing criteria
o The following strategy are used to apply data flow
testing;
1. All-defs
2. All-c-uses
3. All-p-uses
4. All uses
5. All-du-paths
Data flow testing 1
Cont. 9
1. All-defs …
For each variable x and each node n, such that x has a definition in node n,
select a complete path which includes a def-clear path from node n to
• node m having a c-use of x, or
• edge (m, k) having a p-use of x.
Example (partial): Consider tv with its definition in node 2. Variable tv has a c-use in node
4. All-uses
…
o This criterion is the conjunction to the all-p-uses criterion and the all-c-uses criterion.
5. All-du-paths
o For each variable x and for each node n, such that x has a
definition in node n, select complete paths which include all du-paths from node n
• To all nodes m such that there is a c-use of x in m, and
• To all edges (m, k) such that there is a p-use of x on (m, k).
Data flow testing 22
Exercise
def update_values(a, b, flag):
result = 0 # Definition of result
(1) if flag:
a=a+1 # Definition of a
(2)
result = a * b # Use of a, b, Definition of result
(3) else:
b=b-1 # Definition of b (4)
result = a / b # Use of a, b, Definition of result
(5) return result # Use of result
o Apply All-def, All-c-uses, all-p-uses and All-du-
path?
Data flow testing 23
Cont. …
o DFG of source
code
o Definition and uses of DFG
1 start
9 end
Data flow testing
ANY
QUESTION!