Data flow testing is a white-box testing technique that examines the data flow with respect to the variables used in the code. It examines the initialization of variables and checks their values at each instance.
White box testing is a software testing technique that examines the internal working of the software code being developed.
There are two types of data flow testing:
Data flow testing helps catch different kinds of anomalies in the code. These anomalies include:
A few disadvantages of data flow testing are:
Data flow testing can be done using one of the following two techniques:
A control flow graph is a graphical representation of the flow of control, i.e., the order of statements in which they will be executed.
Consider the following piece of pseudo-code:
1. input(x)
2. if(x>5)
3. z = x + 10
4. else
5. z = x - 5
6. print("Value of Z: ", z)
In the above piece of code, if the value of x
entered by the user is greater than 5, then the order of execution of statements would be:
1, 2, 3, 6
If the value entered by the user in line 1 is less than or equal to 5, the order of execution of statements would be:
1, 4, 5, 6
Hence, the control flow graph of the above piece of code will be:
Using the above control flow graph and code, we can deduce the table below. This table mentions the node at which the variable was declared and the nodes at which it was used:
Variable Name | Defined At | Used At |
x | 1 | 2 |
z | 3, 5 | 6 |
We can use the above table to ensure that no anomaly occurs in the code by ensuring multiple tests. E.g., each variable is declared before it is used.
In this technique, we make associations between two kinds of statements:
An association is made with this format:
(line number where the variable is declared, line number where the variable is used, name of the variable)
For example, (1, 3, x) would mean that the variable ‘x’ is defined on line 1 and used on line 3.
Now, consider the following piece of pseudo-code:
1. input(x)
2. if(x>5)
3. z = x + 10
4. else
5. z = x - 5
6. print("Value of Z: ", z)
For the above snippet of pseudo-code, we will make the following associations:
true
case of IF statement in line 2false
case of IF statement in line 2x
is being used in line 3 to define the value of z
x
is being used in line 5 to define the value of z
z
is being used in line 6, which is defined in line 3z
is being used in line 6, which is defined in line 5The first two associations are for the IF statement on line 2. One association is made if the condition is true
, and the other is for the false
case.
Now, there are two types of uses of a variable:
After the associations are made, these associations can be divided into these groups:
Once the associations are divided into these groups, the tester makes test cases and examines each point.
The statements and variables which are found to be extra are removed from the code.
Free Resources