1
Data Flow Testing
2
Introduction
• Dataflow testing refers to forms of structural testing.
• Data-flow testing involves selecting entry/exit paths with the
objective of covering certain data definition and use
patterns, commonly known as data-flow criteria.
• Most programs deliver functionality in terms of data.
• Variables that represent data somehow receive values, and
these values are used to compute values for other variables.
• Since the early 1960s, programmers have analyzed source code
in terms the points at which variables receive values and
points at which these values are used.
3
• Many times, their analyses were based on
concordances(alphabetical list of the words present in a text )
that list statement numbers in which variable names occur.
• Early dataflow analyses often centered on a set of faults that
are now known as define/reference anomalies:
– A variable that is defined but never used
– A variable that is used before it is defined
– A variable that is defined twice before it is used
• Each of these anomalies can be recognized from the
concordance of a program.
4
10.1 Define/Use Testing
• The following definitions refer to a program P that has a
program graph G(P) and a set of program variables V.
• The set of all paths in P is PATHS(P).
• Definitions:
• Node n G (P ) is a defining node of the variable v V , written as
DEF(v, n), iff the value of the variable v is defined at the
statement fragment corresponding to node n.
– E.g. Input statements, assignment statements, loop control
statements, and procedure calls
– When the code corresponding to such statements executes,
the contents of memory location associated with the
variables are changed.
5
• Node n G (P ) is a usage node of the variable v V , written as
USE(v, n), iff the value of the variable v is used at the statement
fragment corresponding to node n.
– E.g. Output statements, assignment statements, conditional
statements, loop control statements, and procedure calls
– When the code corresponding to such statements executes,
the contents of memory location associated with the
variables remain unchanged.
• A usage node USE(v, n), is a predicate use (denoted as P-use) iff
the statement n is a predicate statement, otherwise USE(v, n) is
a computation use (denoted as C-use).
– The nodes corresponding to predicate uses have always an outdegree ≥ 2,
– and nodes corresponding to computation uses always have an
outdegree ≤ 1
6
• A definition-use path with respect to a variable v (denoted
as du-path) is a path in PATHS(P), such that, for somev V ,
there are define and usage nodes DEF(v, m) and USE(v, n)
such that m, and n are the initial and final nodes in the path
respectively.
• A definition-clear path with respect to a variable v (denoted
as dc-path) is a definition-use path in PATHS(P) with initial
and final nodes DEF(v, m) and USE(v, n) such that no other
node in the path is a defining node for v.
7
• An outline of data-flow testing is as follows:
– Draw a data flow graph for the program
– Select data-flow testing criteria
– Identify paths in the data-flow graph to satisfy the
selection criteria (i.e. all-defs, all-uses, all-P-uses/some-C-
uses etc.)
– Produce test cases for the selected paths
8
1.Program Commission (INPUT,OUTPUT)
`
2.Dim locks,stocks,barrels As Integer
3.Dim lockPrice,stockPrice,barrelPrice As Real
4.Dim totalLocks,totalStocks,totalBarrels As Integer
5.Dim lockSales,stockSales,barrelSales As Real
6.Dim sales,commission:REAL
`
7.lockPrice=45.0
8.stockPrice=30.0
9.barrelPrice=25.0
10.totalLocks=0
11.totalStocks=0
12.totalBarrels=0
13.Input(locks)
14.While NOT(locks=-1)
15.Input (stocks,barrels)
16.totalLocks=totalLocks+locks
17.totalStocks=totalStocks+stocks
18.totalBarrels=totalBarrels+barrels
19.Input(locks)
20.EndWhile 9
21.Output(“Locks sold”,totalLocks)
22.Output(“Stocks sold”,totalStocks)
23.Output(“Barrels sold”,totalBarrels)
`
24.lockSales=lockPrice*totalLocks
25.stockSales=stockPrice*totalStocks
26.barrelSales=barrelPrice*totalBarrels
27.sales=lockSales+stockSales+barrelSales
28.Output(“Total sales”,sales)
`
29.If (sales > 1800.0)
30.Then
31.Commission=0.10*1000.0
32.Commission=commission+0.15*800.0
33.Commission=commission+0.20*(sales-1800.0)
34.Else If(sales > 1000.0)
35.Then
36.Commission=0.10*1000.0
37.Commission=commission+0.15*(sales-1000.0)
38.Else
39.commission=0.10*sales
40.EndIf
41.EndIf
42.Output (“Commission is $”,commission)
`
43.End Commission 10
11
12