0% found this document useful (0 votes)
246 views20 pages

Lecture 13 Slice Based Testing by Jorgensen (Autosaved)

Slice-based testing involves creating program slices to test specific parts of a program's behavior. A program slice for a variable v at statement n includes all statements that may affect the value of v at n. Slices are created based on a slicing criterion of (n, v). Well-formed slices must be obtainable from the original program through statement deletion and must correspond to the original program's behavior through the slicing criterion window. Guidelines for effective slice-based testing include creating slices for assignment statements and predicate uses, focusing on one variable per slice, and aiming to make slices compileable.

Uploaded by

Karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views20 pages

Lecture 13 Slice Based Testing by Jorgensen (Autosaved)

Slice-based testing involves creating program slices to test specific parts of a program's behavior. A program slice for a variable v at statement n includes all statements that may affect the value of v at n. Slices are created based on a slicing criterion of (n, v). Well-formed slices must be obtainable from the original program through statement deletion and must correspond to the original program's behavior through the slicing criterion window. Guidelines for effective slice-based testing include creating slices for assignment statements and predicate uses, focusing on one variable per slice, and aiming to make slices compileable.

Uploaded by

Karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Slice- Based Testing

Informal definition of SBT

 A program slice?

 Refers to a set of program statements that


may affect the computation of variable v at
statement number (or node) n
Example
slice of the program w.r.t criterion(10, product)
Formal definition of Slice Based
Testing

 Given a program P, a program graph G(P) in which


statements are numbered, and a set V of variables
in P, the slice on the variable set V at statement n,
S(V,n)
 the set of node (or line) numbers of all statements
fragments in P prior to n that contribute to the values of
variables in V at statement fragment n
Slicing Criterion

 Slicing criterion for a program specifies a window


for observing its behavior
 Where a window
▪ specified as a statement and a set of variables
▪ Allows the observations of values of the specified variables
before execution of particular statement
▪ E.g., S(x, 24) (i.e., value of x at line 24)
Example: The Commission problem in
[Jorgenson02]
 The Commission Problem Statement
 Rifle salesperson in the Arizona Territory sold rifle locks, stocks, and barrels made by a gunsmith in
Missouri. Locks cost $45.00, stocks cost $30.00, and barrels cost $25.00. Salespersons had to sell at
least one complete rifle per month, and production limits are such that the most one salesperson
could sell in one month is 70 locks, 80 stocks, 90 barrels. Each rifle salesperson sent a telegram to the
Missouri company with the total order for each town s/he visits; salespersons visit at least one town
per month, but travel difficulties made ten towns the upper limit. At the end of each month, the
company computed commission as follows:
▪ 10% on sales up to $1000
▪ 15% on the next $800
▪ 20% on any sales in excess of $1800.
 The company had four salespersons. The telegram from each salesperson were sorted into piles (by
person) and at the end of each month a data file is prepared, containing the salesperson's name,
followed by one line for each telegram order, showing the number of locks, stocks, and barrels in
that order. At the end of the sales data lines, there is an entry of “-1” in the position where the
number of locks would be to signal the end of input for that salesperson. The program produces a
monthly sales report that gives the salesperson’s name, the total number of locks, stocks, and
barrels sold, the salesperson's total dollar sales, and finally his/her commission.
Lock has a predicate usage
Alternative definition: Program Slice

 For statement n and variable v, the slice of


program P w.r.t. the slicing criterion <n, v >
includes only those statements of P needed
to contribute (or influence) to the behavior of
v at n.
Simple example

 1 Y := X
 2 Z := Y

 The value of X before the first statement can


contribute to the value of Z after second
▪ S(Z,2)
The notion of contribution: USE
 The notion of contribution can be described by the
USE relationship (e.g., C-use and P-use)

 P-use: used in a predicate (e.g., decision)


 C-use: used in computation (e.g., assignment)
 O-use: used for output (e.g., write/print, etc.)
 L-use: used for location (e.g., pointers/subscripts)
 I-use: used for iteration (e.g., internal counter)
The notion of contribution: Definitions

 Definition nodes can be refined

 I-def: defined by input (e.g., read)


 A-def: defined by assignment statements (e.g., a:= x + y)
Properties of Slice

 There are two properties in a slice

 The slice must have been obtained from the original


program by statement deletion.

 The behavior of the slice must correspond to the


behavior of program as observed through the window
of the slicing criterion
Problem with property one

 By removing the source code of a program, we


may obtain slice that is not grammatically correct.

 E.g. removing the THEN clause from an IF-THEN-ELSE


block
simple guidelines

 First, we assume the set V consists of a single


variable
 Nodes in slice S may include:
 If statement (or node) n is a defining node for v, n is
included in the slice S.
 If statement n is a USE node for v, then n is not included.
 P-Use and C-use of other variables (not the v in the slice
set V) are included if their execution affects the value of
v.
the Commission Problem (1)

loop
the Commission Problem (2)

Compiler defined
the Commission Problem (3)
Good rules of thumb for SBT
1. Never make a slice S(V,n) for which variables v  V
do not appear in statement fragment n
2. Make slices on one variable
3. Make slices for all A-def nodes
e.g.,
S27:S(sales,36)={3,4,5,19,20,21,22,23,24,25,26,27,28,
29,30,36}
4. Make slices for P-use node because the slice shows
how the predicate variable gets its value
5. Stay away from non P-use slices
6. Consider making slices compile-able (executable)`

You might also like