Data Flow Testing Strategies - Good Example
Data Flow Testing Strategies - Good Example
com
Abstract
Control flow diagrams are a keystone in testing the In data-flow testing, the first step is to model the
structure of software programs. By examining the flow of program as a control flow graph. This helps to identify
control between the various components, we can design the control flow information in the program. In step 2, the
and select test cases. Data-flow testing is a control-flow associations between the definitions and uses of the
testing technique which also examines the lifecycle of variables that is needed to be covered in a given coverage
data variables. Use of data-flow testing leads to a richer criterion is established. In step 3, the test suite is created
test suite concentrating on improper use of data due to using a finite number of paths from step 2.
coding errors. The main goal of this paper is to discuss In this paper, we have discussed the concept of data-
the concept of data-flow testing and apply it to a running flow testing. The next section covers the data-flow testing
example. criteria and data-flow anomalies. A billing application is
considered and the corresponding control-flow graphs are
Keywords: Data-flow testing, control-flow graph, Data- presented and annotated to explain the concept of data-
flow anomaly. flow testing. Section 3 presents the test cases created for
this application. Section 4 summarizes the concepts
1. Introduction presented in this paper and concludes the paper.
2.1. Data-flow Anomalies applicable. If ‘Bill’ is more than $100, 10% discount is
given.
Data-flow anomalies represent the patterns of data
usage which may lead to an incorrect execution of the Table 2: Billing rules
code. Usage(min) Bill ($)
The notation for representing the patterns is [2][5]:
<100 40.0
50 cents for every additional
• d – defined, created, initialized 101-200 minute.
• k – killed, terminated, undefined 10 cents for every additional
• u – used >200 minute.
o c – used in a computation
o p – used in a predicate
• ~x - indicates all prior actions are not of interest The source code for the above application is:
to x
• x~ - indicates all post actions are not of interest public static double calculateBill (int Usage)
to x {
double Bill = 0;
Table 1 lists the combinations of usage and their
corresponding consequences. It can be observed that not if(Usage > 0)
all data-flow anomalies are harmful but they are all {
Bill = 40;
suspicious and indicate that an error can occur. For }
example, the usage pattern ‘ku’ indicates that a variable is if(Usage > 100)
used after it has been killed which is a serious defect. {
if(Usage <= 200)
{
Table 1: Testing anomalies [1][6] Bill = Bill + (Usage - 100) * 0.5;
Anomaly Explanation }
else
~d first define Allowed. {
du define – use Allowed. Normal case. Bill = Bill + 50 + (Usage - 200) * 0.1;
dk define – kill Potential bug. Data is killed if(Bill >= 100)
without use after definition. {
Bill = Bill * 0.9;
~u first use Potential bug. Data is used without }
definition. }
ud use – define Allowed. Data is used and then }
redefined. return Bill;
}
uk use – kill Allowed.
~k first kill Potential bug. Data is killed before
definition. The control flow diagram is given in Figure 1 and the
ku kill – use Serious Defect. Data is used after annotated control flow diagram with define-use-kill
being killed. information for each variable is given in Figure 2.
kd kill – define Allowed. Data is killed and then
re-defined. For variable ‘Usage’, the define-use-kill patterns are
dd define–define Potential bug. Double definition. • ~ define : normal case
uu use – use Allowed. Normal case. • define-use : normal case
kk kill – kill Potential bug. • use-use : normal case
d~ define last Potential bug. • use-kill : normal case
u~ use last Allowed.
k~ kill last Allowed. Normal case. For variable ‘Bill’, the define-use-kill patterns are
• ~ define : normal case
2.2. Static Data-flow Testing • define-define: suspicious
• define-use : normal case
With static analysis, the source code is analyzed • use-define : acceptable
without executing it [6]. Let us consider an example of an • use-use : normal case
application to calculate the bill of a cellular service • use-kill : normal case
customer depending upon on his/her usage. The following
calculates ‘Bill’ as per ‘Usage’ with the following rules
9. use Bill
10. use Bill
define Bill
2.
Y 3. Bill = 40 11. Kill Bill
Usage > 0
Y All-Uses (AU)
Formal Definition
4. 5. ‘At least one path from every definition of every variable
use Usage use Usage
to every use of that can be reached by that definition’ [7].
All-p-uses/Some-c-uses (APU+C)
Formal Definition
2.3. Dynamic Data-flow Testing ‘For every variable and every definition of that variable,
include at least one path from the definition to every
The primary purpose of dynamic data-flow testing is to predicate use; if there are definitions of the variable that
uncover possible bugs in data usage during the execution are not covered then add computational use test cases as
of the code. To achieve this, test cases are created which required to cover every definition’ [7].
trace every definition to each of its use and every use is
traced to each of its definition. Various strategies are In this testing strategy, for every variable, there is a path
employed for the creation of the test cases [4][5]. The from every definition to every p-use of that definition. If
definition of all strategies is followed by an example to there is a definition with no p-use following it, then a
explain the same. c-use of the definition is considered.
All-definition (AD)
Formal Definition
‘Every definition of every variable be covered by at least
one use of that variable, be that use a computational use
or a predicate use’.
0. def
1.
2.
Y 3.
p - use
4. 5.
p - use p - use
N 7. 6. c - use
Y
N
8.
10. 9. c - use
11.
Figure 4.Annotated Control Flow diagram for Figure 5.Annotated Control Flow diagram for
variable ‘Bill’ variable ‘Usage’
Table 5: Data-flow testing paths for each variable In case of All c-uses/Some p-uses, we observe that the
Strategy Bill Usage paths are similar to All c-uses since every definition has a
All uses 3-4-5-6 0-1-2 corresponding c-use.
(AU) 6-7 0-1-2-3-4 In case of All p-uses/Some c-uses, definitions in 8 and 9
6-7-8 0-1-2-3-4-5 don’t have a corresponding p-use, hence c-use in 10 is
8-10 0-1-2-3-4-5-6 considered.
3-4-5-9 0-1-2-3-4-5-9 For All uses, we trace a path to all the uses (c-use and p-
use).
All p – uses 1-2-3-4-5-6-7 0-1-2
(APU) 3-4-5-6-7 0-1-2-3-4 2.4. Ordering of Strategies
6-7 0-1-2-3-4-5
For selection of test cases, we need to analyze the
relative strength of the data-flow testing strategies. Figure
All c – uses 1-2-10 0-1-2-3-4-5-6 6 depicts the relative strength of the data-flow strategies
(ACU) 3-4-5-6 0-1-2-3-4-5-9 and other control-flow testing strategies such as all-
3-4-5-9 branch and all-statement. According to the figure, the
3-4-10 strength of testing strategies reduces along the direction
6-7-8 of the arrow. Hence ALL PATHS is the strongest testing
6-7-10 strategy. Also note that ACU+P and APU+C run parallel
8-10 hence they are comparable [7].
9-10
All p – use/ 1-2-3-4-5-6-7 0-1-2
some c 3-4-5-6-7 0-1-2-3-4
(APU + C) 6-7 0-1-2-3-4-5
8-10
9-10 ALL PATHS
STATEMENT
Table 6. Test Suite for variable ‘Bill’ Table 7. Test Suite for variable ‘Usage’
Input Input
Expected Expected
Uses Bill Usage Uses Usage Usage
Value Value
Value Value
All 1-2-10 0 0.0 All definition 0-1-2 0 0.0
definition 3-4-5-6 220 92.0 (AD)
(AD) 6-7 220 92.0
8-10 350 94.5 All c – use 0-1-2-3-4- 220 92.0
9-10 220 92.0 (ACU) 5-6 170 75.0
All c – use 1-2-10 0 0.0 0-1-2-3-4-
(ACU) 3-4-5-6 220 92.0 5-9
6-7-8 350 94.5 All p – use 0-1-2 0 0.0
8-10 350 94.5 (APU) 0-1-2-3-4 170 75.0
9-10 220 92.0 0-1-2-3-4-5 170 75.0
5. References 6. Appendices
[1] Tsai, B.-Y.; Stobart, S.; Parrington, N.; “Employing data Appendix A: Glossary
flow testing on object-oriented classes”, Software, IEEE
Proceedings, USA, April 2001, p 56-64-87.
Black-box testing – The use of specifications of a unit,
[2] Harrold M Jean.; Rothermel Gregg.; “Performing data flow subsystem, or system to design tests. It is synonymous
testing on classes”, ACM SIGSOFT Software Engineering with specification-based testing or functional testing. [8]
Notes , Proceedings of the 2nd ACM SIGSOFT symposium on
Foundations of software engineering SIGSOFT’94, December Branch coverage – Branch coverage is achieved when
1994, pp 154 - 163. every path from a control flow graph node has been
executed at least once by a test suite. [8]
[3] Chang Liu; “Teaching “Data Flow Testing” in an Software
Engineering Course”, School of Electrical Engineering and
Computer Science, Russ College of Engineering and
Data-Flow Anomaly – A data-flow anomaly is denoted
Technology, Ohio University. by a two-character sequence of actions [7].
[4] Rapps, Sandra, Elaine J. Weyuker; “Data Flow Analysis Data-Flow Testing – It selects paths through the
Techniques for Test Data Selection”, Sixth International program’s control flow in order to explore sequences of
Conference on Software Engineering, Tokyo, Japan, September events related to the status of data objects [7].
13-16, 1982.
State - The state of an object can be defined as a set of
[5] Parrish, A.S.; Zweben, S.H.; “On the relationships among
instance variable value combinations that share some
the all-uses, all-DU-paths, and all-edges testing criteria”,
Software Engineering, IEEE Transactions, 1995, p 1006-1009.
property of interest. [8]