data flow testing (dft) data flow testing is not the same as constructing design diagrams in the...

14
Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is a form of structural testing and mostly White Box testing technique that focuses on program variables and the data paths : From the point where a variable, v, is defined or assigned a value To the point where that variable, v, is used Remember, to generate the path for testing we need to set up the data to drive the path.

Upload: heather-peters

Post on 17-Dec-2015

237 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Data Flow Testing (DFT)

• Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams.

• It is a form of structural testing and mostly White Box testing technique that focuses on program variables and the data paths:

– From the point where a variable, v, is defined or assigned a value– To the point where that variable, v, is used

Remember, to generate the path for testing we need to set up thedata to drive the path.

Page 2: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Static Analysis of Data

• Static analysis allows us to check (test or find faults) without running the actual code, and we can apply it to analyzing variables as follows:

1. A data item(variable) that is defined but never used 2. A data item that is used but never defined3. A data item that is defined a multiple times prior to usage.

• While these are dangerous signs, they may or may not lead to defects.

1. A defined, but never used variable may just be extra stuff2. Some compilers will assign an initial value of zero or blank to all undefined

variable based on the data type.3. Multiple definitions prior to usage may just be bad and wasteful logic

• We are more interested in “executing” the code than just static analysis, though.

Page 3: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Data Dependencies and Data Flow Testing(DFT)

• In Data Flow Testing (DFT) we are interested in the “dependencies” among data or “relationships” among data ----- Consider a data item, X:

– Data Definitions (value assignment) of X: via 1) initialization, 2) input, or 3) some assignment.• Integer X; (compiler initializes X to 0 or it will be “trash”)• X = 3;• Input X;

– Data Usage (accessing the value) of X: for 1) computation and assignment (C-Use) or 2) for decision making in a predicate (P-Use)• Z = X + 25; (C-Use)• If ( X > 0 ) then ----- (P-Use)

Page 4: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Data “Dependencies” or Data “Relationships”

• There are basically 4 possible combinations of “relationships” between data Definition (D) and data Usage (U). For example for a data item, X:

1. D-U : relationship between X defined and X used afterwards (**this is the main relationship of concern for Data Flow Testing).

2. D–D: relationship between X is defined and is redefined with no usage in between ( a case of potential error or in multiple & parallel paths execution of a potential race condition)

3. U-D: relationship between X is used first and then defined afterward ( a case of potential error)

4. U-U: relationship between X being used and used again later (there is no impact to X and thus not considered for testing)

Page 5: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Main Steps in Data Flow Testing

• The main steps in Data Flow Testing are:

1. Build and Verify the Data Dependency Graph (DDG)2. Define and select the data slice of interest to cover for

developing the test case3. Develop the test case by selecting/deciding on what

input values to use (the key to DFT)4. Execute the test case and analyze the result.

Page 6: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

A simple Data Dependency Graph(DDG)

• Instead of control flow as in execution paths, we use the data and depict the “flow of data” or “relation among data”

• Example: integer x, y, z; input x, y;

z = y + x;

x y

z

- The nodes (circle) represent data items.- The links (arrow) represent the flow of x and y to z or dependency of z on x and y

Page 7: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Characterizing Data Dependency Graph(DDG)

• We are mostly interested in D-U relationship when performing DFT:

– Each node in a Data Dependency Graph (DDG) represents, a data item, x and the nodes may be classified in 3 ways:

• Output or result node of some computation or assignment. This node will most likely express x in terms of (linked-from) some other node.

• Input or constant node that represents x as the user provided input or a pre-defined constant. It usually links-to some other node

• Intermediate or storage node where x is neither an input or output; x is most likely an intermediate storage (C-Use) to facilitate some computation. It usually will both link-from some other node and link-to some other node.

– The relation modeled is D-U, and the linkage arrow from x to z depicts x “is used by” z.

Page 8: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Data Used in Predicate Node for (P-Use)

• Data used for P-use is depicted a little differently:

- consider a “segment”: input w; if w ≥ 3 then z = x; else z = y;

x y

zw≥3

3w

w≥3 / w<3

w≥3 w<3

-Note that data item, w, is used mainly for P-use.-Note that constant 3 is also used for P-use.-The dotted arrow depicts the relation of P-use

Page 9: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Generating inputs to Drive the Data FlowTest

• The basic concept in DFT is to design test cases (with the appropriate inputs) to cover the D-U relationships in the DDG:– C-use– P-use

x y

zw≥3

3w

w≥3 / w<3

w≥3 w<3

1) We need to design test cases with data items ‘x’ and ‘y’“defined” for C-use and different values of data item ‘w’ defined for P-use.

2) Then display ‘z‘ for the test result analysis.

Page 10: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Generic Procedure for DDG Construction

1. Indentify the output or result data items of interest2. Backward chain to resolve (trace) these data items using

other data items (both variables and constants)by consulting the source (program, pseudo code, specification).

– This backward chain is often called a “slice” ---- a “data slice”

3. If there is any unresolved data item during the trace, then for that unresolved variable repeat the above steps 1 and 2. Perform this until there is no unresolved data item left.

Note - i) with this construction mechanism all the “leaf” nodes at the “top“ of a DDG must be an “input/assignment” data item node or a “constant” data item node - ii) that we may need to stepwise construct several DDG’s for a complete specification - iii) that if we have a node that is disconnected to any DDG’s or nodes, then that is likely a “dead node” which is extraneous and potentially an error

Page 11: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

An “awkward” Data Dependency Graph Example

• Pseudo code example

• 1. int limit = 10;• 2. input y ;• 3. input x ;• 4. for (int i = 1; i < limit ; i++)• 5. { x = x + i;• 6. y = y + i2 ; } • 7. print (“ x = “, x , “y =“, y);

10

1

limit

i

i++

i < limit

i 2

y x

y + i 2

x + i

print y

print x Note the “awkwardness” of DDG when there is a loop

Page 12: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

A “awkward” Data Dependency Graph Example

• Pseudo code example

• 1. int limit = 10;• 2. input y ;• 3. input x ;• 4. for (int i = 1; i < limit ; i++)• 5. { x = x + i;• 6. y = y + i2 ; } • 7. print (“ x = “, x , “y =“, y);

10

1

limit

i

i++

i < limit

i 2

y x

y + i 2

x + i

print y

print x Note the “awkwardness” of DDG when there is a loop ; also look at “i++” more carefully-----

Page 13: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Picking up a “data slice” related to “print y”

• Pseudo code example

• 1. int limit = 10;• 2. input y ;• 3. input x ;• 4. for (int i = 0; i < limit ; i++)• 5. { x = x + i;• 6. y = y + i2 ; } • 7. print (“ x = “, x , “y =“, y);

10

1

limit

i

i++

i < limit

i 2

y x

y + i 2

x + i

print y

print xUsing the DDG to follow the D-Upaths in a data slice.

Page 14: Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is

Picking up a “slice” related to “print y”

• Pseudo code example

• 1. int limit = 10;• 2. input y ;• 3. input x ;• 4. for (int i = 1; i < limit ; i++)• 5. { x = x + i;• 6. y = y + i2 ; } • 7. print (“ x = “, x , “y =“, y);

limit = 10

Input y

Input x

i = 1

x = x + i

y = y +i2

i = i + 1

i < limit

print y

print x

** Some finds the “control flow” a little easier to follow than the “data dependency” when we are looking at D-U “paths” of data.