You are on page 1of 9

STRUCTURAL TESTING

Slice Based Testing

Slice Based Testing

Introduced by Mark Weiser.

Prepares various subsets


(called slices) of program with
respect to its variables and
their selected locations in the
program.

Slices are simpler than the


original program and simplify
the process of testing of the
program.

Slice Based Testing


A slice S(v,n) of program P on
variable v, or set of variables, at
statement n yields the portions of
the program that contributed to the
value of v just before statement n
is executed.
S(v,n) is called slicing criteria.
Slice is an executable program.

Slice Based Testing


GUIDELINES FOR SLICING
All statements where variables are defined and
redefined should be considered.

All statements where variables are receiving


values externally should be considered.

All statements where output of a variable is printed


should be considered.

Slice Based Testing


GUIDELINES FOR SLICING
All the statements where relevant output is printed
should be considered.

The status of all variables may be considered at


last statement of the program.

Slice Based Testing


Consider the following portion of a program:
1.a=3;
2.b=6;
3.c=b2;
4.d=a2+b2;
5.c=a+b;

Slice Based Testing


S(c,5)

S(c,3)

1. a=3;

2. b=6;

2. b=6;

3. c=b2;

5. c=a+b;

Slice Based Testing


Consider the following program. Create slices based on slicing criterion.
1. void main()
2. {
3. int a,b,c,d,e;
4. printf(Enter the values of a,b, and c\n);
5. scanf(%d %d %d,&a,&b,&c);
6. d=a+b;
7. e=b+c;
8. printf(%d,d);
9. printf(%d,e);
10.}

Slice Based Testing


Consider the program to find largest number
amongst three numbers. Create slices on the
variables and generate test cases.

Slice Based Testing


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

void main()
{
float A,B,C;
clrscr();
printf("Enter number 1:\n");
scanf("%f", &A);
printf("Enter number 2:\n");
scanf("%f", &B);
printf("Enter number 3:\n");
scanf("%f", &C);
if(A>B) {
if(A>C) {
printf("The largest number is: %f\n",A);
}
else {
printf("The largest number is: %f\n",C);
}
}
else {
if(C>B) {
printf("The largest number is: %f\n",C);
}
else {
printf("The largest number is: %f\n",B);
}
}
getch();
}

Slice Based Testing


1.

S(A,6)=(1,2,3,4,5,6,28)

2.

S(A, 13)=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,27,28)

3.

S(A, 28)=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,27,28)

4.

S(B, 8)=(1,2,3,4,7,8,28)

5.

S(B, 24)=(1,2,3,4,5,6,7,8,9,10,11,19,20,23,24,25,26,27,28)

6.

S(B, 28)=(1,2,3,4,5,6,7,8,9,10,11,19,20,23,24,25,26,27,28)

7.

S(C, 10)=(1,2,3,4,9,10,28)

8.

S(C, 16)=(1,2,3,4,5,6,7,8,9,10,11,12,15,16,17,18,27,28)

9.

S(C, 21)=(1,2,3,4,5,6,7,8,9,10,11,19,20,21,22,26,27,28)

10. S(C, 28)=(1,2,3,4,5,6,7,8,9,10,11,19,20,21,22,26,27,28)

Slices for the given program

Slice Based Testing


1
2
3
4
5
6
7
8
9
10
11
12
13
14
18
27
28

#include<stdio.h>
#include<conio.h>
voidmain()
{
floatA,B,C;
clrscr();
printf("Enternumber1:\n");
scanf("%f",&A);
printf("Enternumber2:\n");
scanf("%f",&B);
printf("Enternumber3:\n");
scanf("%f",&C);
if(A>B){
if(A>C){
printf("Thelargestnumberis:%f\n",A);
}
}
getch();
}

S(A,28)=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,27,28)

Slice Based Testing


1
2
3
4
5
6
7
8
9
10
11
13
19
20
22
23
24
25
26
27
28

#include<stdio.h>
#include<conio.h>
voidmain()
{
floatA,B,C;
clrscr();
printf("Enternumber1:\n");
scanf("%f",&A);
printf("Enternumber2:\n");
scanf("%f",&B);
printf("Enternumber3:\n");
scanf("%f",&C);
if(A>B){/*donothing*/
}
else{
if(C>B){/*donothing*/
}
else{
printf("Thelargestnumberis:%f\n",B);
}
}
getch();
}
S(B,28)=(1,2,3,4,5,6,7,8,9,10,11,19,20,23,24,25,26,27,28)

Slice Based Testing


1
2
3
4
5
6
7
8
9
10
11
18
19
20
21
22
26
27
28

#include<stdio.h>
#include<conio.h>
voidmain()
{
floatA,B,C;
clrscr();
printf("Enternumber1:\n");
scanf("%f",&A);
printf("Enternumber2:\n");
scanf("%f",&B);
printf("Enternumber3:\n");
S(C, 28)=(1,2,3,4,5,6,7,8,9,10,11,19,20,21,22,26,27,28)
scanf("%f",&C);
if(A>B){/*donothing*/
}
else{
if(C>B){
printf("Thelargestnumberis:%f\n",C);
}
}
getch();
}

Slice Based Testing


S. No

Slice

Paths

Expected
output

S(A, 6)

1,2,3,4,5,6,28

S(A, 13)

1,2,3,4,5,6,7,8,9,10,11,12,
13,14,18,27,28

S(A, 28)

1,2,3,4,5,6,7,8,9,10,11,12,
13,14,18,27,28

S(B, 8)

1,2,3,4,7,8,28

S(B, 24)

1,2,3,4,5,6,7,8,9,10,11,19,
20,23,24,25,26,27,28

8
9

Slice Based Testing


S. No
6

Slice
S(B, 28)

Paths
1,2,3,4,5,6,7,8,9,10,11,19,
20,23,24,25,26,27,28

S(C, 10)

1,2,3,4,9,10,28

S(C, 16)

1,2,3,4,5,6,7,8,9,10,11,12,
15,16,17,18,27,28

S(C, 21)

10

S(C, 28)

Expected
output

8
8

1,2,3,4,5,6,7,8,9,10,11,19,
20,21,22,26,27,28

1,2,3,4,5,6,7,8,9,10,11,19,
20,21,22,26,27,28

Slice Based Testing


It focuses on a portion of a program with respect
to a variable location in any statement of the
program.
Slicing cannot test a behaviour which is not
represented by a set of variables or a variable of
the program.

You might also like