0% found this document useful (0 votes)
2 views

Data Flow Testing and Program Slicing

The document discusses data flow testing, a white-box testing technique that analyzes the flow of data and variables in code, highlighting its types (static and dynamic), advantages, and disadvantages. It also covers program slicing, which focuses on specific program statements affecting variable values, distinguishing between static and dynamic slicing. Techniques such as control flow graphs and variable association are explained to aid in identifying anomalies and optimizing testing processes.

Uploaded by

Hamza Main
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Data Flow Testing and Program Slicing

The document discusses data flow testing, a white-box testing technique that analyzes the flow of data and variables in code, highlighting its types (static and dynamic), advantages, and disadvantages. It also covers program slicing, which focuses on specific program statements affecting variable values, distinguishing between static and dynamic slicing. Techniques such as control flow graphs and variable association are explained to aid in identifying anomalies and optimizing testing processes.

Uploaded by

Hamza Main
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Data flow testing and

program slicing
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.
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 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 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.
Program slicing
• Slicing or program slicing is a technique used in software testing
which takes a slice or a group of program statements in the program
for testing particular test conditions or cases that may affect a value
at a particular point of interest. It can also be used for the purpose of
debugging in order to find the bugs more easily and quickly.
• Slicing techniques were originally defined by Mark
Weiser and they were only static in nature at that time.
Afterward, Bogdan Korel and Janusz Laski introduced
dynamic slicing, which can work for a particular
execution of the program.
It is of 2 types: static slicing and dynamic slicing, these
are explained as following below:
• 1. Static slicing:

• A static slice of a program contains all statements that may affect the
value of a variable at any point for any arbitrary execution of the
program.
• Static slices are generally larger.
• It considers every possible execution of the program.
• 2. Dynamic slicing:
• A dynamic slice of a program contains all the statements that actually
affect the value of a variable at any point for a particular execution of
the program.
• Dynamic slices are generally smaller.
• Considers only a particular execution of the program.
Code example
• int z = 10;
• int n;
• cin >> n;
• int sum = 0;
• if (n > 10)
• sum = sum + n;
• else
• sum = sum - n;
• cout << "Hey";
• Static slice for the variable sum:
int n;
• cin >> n;
• int sum = 0;
• if (n > 10)
• sum = sum + n;
• else
• sum = sum - n;
• Dynamic slice for the variable sum when n = 22;
int n;
• cin >> n;
• int sum = 0;
• if (n > 10)
• sum = sum + n;
• As it can be observed in the above example the static slice takes all
the possible execution (in this case it is 2) of the program which may
affect the value of the variable sum. Whereas in the case of dynamic
slicing, it considers only a particular execution (when n = 22) of the
program which actually affects the value of the variable sum.
• Hence, the dynamic slice is always smaller than a static slice.

You might also like