What is data flow testing?

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.

Types of data flow testing

There are two types of data flow testing:

  • Static data flow testing: The declaration, usage, and deletion of the variables are examined without executing the code. A control flow graph is helpful in this.
  • Dynamic data flow testing: The variables and data flow are examined with the execution of the code.

Advantages of data flow testing

Data flow testing helps catch different kinds of anomalies in the code. These anomalies include:

  • Using a variable without declaration
  • Deleting a variable without declaration
  • Defining a variable two times
  • Deleting a variable without using it in the code
  • Deleting a variable twice
  • Using a variable after deleting it
  • Not using a variable after defining it

Disadvantages of data flow testing

A few disadvantages of data flow testing are:

  • Good knowledge of programming is required for proper testing
  • Expensive
  • Time consuming

Techniques of data flow testing

Data flow testing can be done using one of the following two techniques:

  • Control flow graph
  • Making associations between data definition and usages

Control flow graph

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.

Making associations

In this technique, we make associations between two kinds of statements:

  • Where variables are defined
  • Where those variables are used

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:

  • (1, (2,t), x): for the true case of IF statement in line 2
  • (1, (2,f), x): for the false case of IF statement in line 2
  • (1, 3, x): variable x is being used in line 3 to define the value of z
  • (1, 5, x): variable x is being used in line 5 to define the value of z
  • (3, 6, z): variable z is being used in line 6, which is defined in line 3
  • (5, 6, z): variable z is being used in line 6, which is defined in line 5

The 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:

  • predicate use: the use of a variable is called p-use. Its value is used to decide the flow of the program, e.g., line 2.
  • computational use: the use of a variable is called c-use when its value is used compute another variable or the output, e.g., line 3.

After the associations are made, these associations can be divided into these groups:

  • All definitions coverage
  • All p-use coverage
  • All c-use coverage
  • All p-use, some c-use coverage
  • All c-use, some p-use coverage
  • All uses coverage

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

Copyright ©2024 Educative, Inc. All rights reserved