08 Slice based Testing - skylerto/Software-Testing GitHub Wiki
Slice-based Testing
The point of program slice
- Analyze a program by focusing on parts of interest, disregarding uninteresting parts
- The point of slices is to separate a program into components that have a useful functional meaning
- Ignore those parts that do not contribute to the functional meaning of interest
- Cannot do this with du-paths, as slices are not simply sequences of statements or statement fragments
(Static) Program slice
- What is a program slice?
- A program slice is a set of program statements that contributes to or affects the value of a variable at some point in a program
- Backward slices S(v, n): refer to statement fragments that contribute to the value of v at statement n
- Statement n is a Use node of variable v, Use (v, n)
- Forward slices S(v, n): refer to all the program statements that are affected by the value of v and statement n
- Refers to the predicate uses and computation uses of the variable v


Dynamic Slicing
- Static slicing can be used to assist debugging by simplying the program. However, the slices constructed by slicing can be very large.
- A dynamic slice is constructed with respect to the traditional static slicing criterion together with dynamic information (the input sequence supplied to the program, during some specific execution). Three piece of information (dynamic slicing criterion)
- Variables to be sliced (same as static slicing)
- The point of interest within the program (same as static
slicing)
- Sequence of input values for which the program was executed
- “A dynamic slice for a variable at statement n, on an input I
Static vs. Dynamic Slicing
- Static slices will typically be larger, but will cater for every possible execution of the original program
- Dynamic slices will typically be much smaller, but they will only cater for a single input
- Code reuse:
- Reusing part of a program which implements a well- tested approach to some problem. Often in such situations (especially for legacy code), the code we want to reuse will be intermingled with all sort of other unrelated code.
- Static slicing is ideal as a technique for extracting the part of the program we require, while leaving behind the part of the program that we are not interested in

Applications of program slicing
- Program comprehension
- Debugging
- Measuring the function cohesion
- Software maintenance and evolution
Tools
Java (static slicing only)
C/C++