Open In App
Related Articles

Software Engineering | Slicing

Improve Article
Improve
Save Article
Save
Like Article
Like

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.

Let us see an example by the given code snippet:
 

CPP




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
 

CPP




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; 
 

CPP




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.
 


Master Software Testing and Automation in an efficient and time-bound manner by mentors with real-time industry experience. Join our Software Automation Course and embark on an exciting journey, mastering the skill set with ease!
What We Offer:
  • Comprehensive Software Automation program
  • Expert Guidance for Efficient Learning
  • Hands-on Experience with Real-world Projects
  • Proven Track Record with 10,000+ Successful Geeks

Last Updated : 16 Feb, 2022
Like Article
Save Article
Previous
Next
Similar Reads