0% found this document useful (0 votes)
3 views

CH 4 part II

The document discusses data flow testing, a white box testing method that analyzes the flow of data within a program to identify potential anomalies and ensure proper handling of variables. It outlines the types of data flow testing, including static and dynamic approaches, and highlights the benefits such as increased code coverage and improved reliability. Additionally, it explains various data flow anomalies and testing criteria, providing examples and a structured procedure for conducting data flow testing.

Uploaded by

hanayaregal13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CH 4 part II

The document discusses data flow testing, a white box testing method that analyzes the flow of data within a program to identify potential anomalies and ensure proper handling of variables. It outlines the types of data flow testing, including static and dynamic approaches, and highlights the benefits such as increased code coverage and improved reliability. Additionally, it explains various data flow anomalies and testing criteria, providing examples and a structured procedure for conducting data flow testing.

Uploaded by

hanayaregal13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Software testing

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

Benefit of data flow testing


o Data flow testing find the following issues
• Increased code coverage: It ensures that all definitions and uses of variables
are tested.
• Improved reliability: By ensuring correct use of variables, you can
catch potential errors related to uninitialized or incorrectly modified
variables.
• Helps detect unused code: If certain definitions or variables aren’t used, they
might indicate unnecessary code that should be refactored.
• Effective debugging
• Data flow testing detect improper use of data values due to coding errors.
Data flow testing 8

Type of data flow testing


o Static data flow testing
• Identify potential defects, commonly known as data flow
anomaly.
• Analyze source code.
• Do not execute code.
o Dynamic data flow testing
 Involves actual program execution.
 Bears similarity with control flow testing.
• Identify paths to execute them.
• Paths are identified based on data flow testing criteria.
Data flow testing 9

Data flow anomaly


o Anomaly: It is an abnormal way of doing something.
• For example, it is an abnormal situation to successively assign two values to a
variable without using the first value.
o Early data flow analysis often centered on a set of faults that are now known as
define/reference anomalies.
o There are 3 type of anomaly when using variable. Those are
1. dd anomaly: Defined twice before used
2. du anomaly: Defined but never used/referenced
3. ud anomaly: Used before defined
Data flow testing 1
Cont. 0
o Type 1: dd - Defined and then defined again …
• Example 1: The second definition of x overrides the first.

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

o Type 3: Defined but not referenced



• A third kind of data flow anomaly is to define a variable and then to undefine it
without using it in any subsequent computation.
• Example: Consider x = f(x, y). in which a new value is assigned to the variable
x.
• If the value of x is not used in any subsequent computation, then we should be
suspicious of the computation represented by x = f (x, y). Hence, this form of
anomaly is called “defined but not referenced.
Data flow testing 1
Data flow testing procedure 2

o Data flow testing is outlined as follows:


• Draw a data flow graph from a program.
• Select one or more data flow testing criteria.
• Identify paths in the data flow graph satisfying the selection
criteria.
• Derive path predicate expressions from the selected paths .
• Solve the path predicate expressions to derive test inputs.
Data flow testing 1
3
Definition and uses
o Example of def and use
Def P-use

1. read (x, y); C-use


x,
2. z = x + 2;
yz x
3. if (z < y)
4 w = x + 1; z,
w y
else
5. y = y + 1; x
6. print (x, y, w, y
z); y
x, y, w, z
Data flow testing 1
Data 4

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),

• If x has been neither defined nor undefined in nodes n1 … nm.


• Example: (2 – 3 – 4 – 6 – 3 – 4 – 6 – 3 – 4 – 5) is a def-clear path w.r.t. tv .
• Example: (2 – 3 – 4 – 5) and (2 – 3 – 4 – 6) are def-clear
paths w.r.t. variable tv from node 2 to 5 and from node 2 to 6,
respectively
o Simply, x is not defined at any of the nodes between node n and node m.
Data flow testing 1
Cont. 7

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

5, and there is a def-clear path (2 – 3 – 4 – 5) from node 2 to node 5. Choose a


complete
path (1 – 2 – 3 – 4 – 5 – 6 – 3 – 7 – 9 – 10) that includes the def-clear path (2 – 3 – 4 – 5)
to satisfy the all-defs criterion.
Data flow testing 20
Cont.
2. All-c-uses …
• For each variable x and each node n, such that x has a definition in node n, select complete
paths which include def-clear paths from node n to all nodes m such that there is a c-use of x
in m.
• Example (partial): Consider variable ti, which has a definition in 2 and a c-use in node 4.
From node 2, the def-clear path to 4 is (2 – 3 – 4). One may choose the complete path (1 – 2 –
3 – 4 – 6 – 3 – 7 – 8 – 10).
3. All-p-uses
• For each variable x and each node n, such that x has a definition in node n, select complete paths
which include def-clear paths from node n to all edges (m, k) such that there is a p-use of x on
(m, k).
• Example (partial): Consider variable tv, which has a definition in 2 and p-uses on edges (7, 8)
and (7, 9). From node 2, there are def-clear paths to (7, 8) and (7, 9), namely (2 – 3 – 7 – 8) and
(2 – 3 – 7 – 9). The two complete paths are: (1 – 2 – 3 – 7 – 8 – 10) and (1 – 2 –3 – 7 – 9 – 10).
Data flow testing 2
Cont. 1

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

var Defined at Used at node


2 Result = 0; node

3 If flag a Start,4 4,5,7


T
F

else b = b -1; 6 4 a=a+1 b Start,6 5,6,7

7 5 result = a * b; flag start 3


result = a / b;

8 return result; result 1,5,7 8

9 end
Data flow testing

ANY
QUESTION!

You might also like