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 void main()
2 {
3 float A,B,C;
4 clrscr();
5 printf("Enter number 1:\n");
6 scanf("%f", &A);
7 printf("Enter number 2:\n");
8 scanf("%f", &B);
9 printf("Enter number 3:\n");
10 scanf("%f", &C);
11 if(A>B) {
12 if(A>C) {
13 printf("The largest number is: %f\n",A);
14 }
15 else {
16 printf("The largest number is: %f\n",C);
17 }
18 }
19 else {
20 if(C>B) {
21 printf("The largest number is: %f\n",C);
22 }
23 else {
24 printf("The largest number is: %f\n",B);
25 }
26 }
27 getch();
28 }
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


#include<stdio.h>
#include<conio.h>
1 void main()
2 {
3 float A,B,C;
4 clrscr();
5 printf("Enter number  1:\n");
6 scanf("%f", &A);
7 printf("Enter number  2:\n");
8 scanf("%f", &B);
9 printf("Enter number  3:\n");
10 scanf("%f", &C);
11 if(A>B) {
12 if(A>C) {
13 printf("The largest number is: %f\n",A);
14 }
18 }
27 getch();
28 }
S(A, 28) =(1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,27,28)
Slice Based Testing
#include<stdio.h>
#include<conio.h>
1 void main()
2 {
3 float A,B,C;
4 clrscr();
5 printf("Enter number  1:\n");
6 scanf("%f", &A);
7 printf("Enter number  2:\n");
8 scanf("%f", &B);
9 printf("Enter number  3:\n");
10 scanf("%f", &C);
11 if(A>B) { /*do nothing*/
13 }
19 else   {
20 if(C>B) { /*do nothing*/
22 }
23 else    {
24 printf("The largest number is: %f\n",B);
25 }
26 }
27 getch();
28 }
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


#include<stdio.h>
#include<conio.h>
1 void main()
2 {
3 float A,B,C;
4 clrscr();
5 printf("Enter number  1:\n");
6 scanf("%f", &A);
7 printf("Enter number  2:\n");
8 scanf("%f", &B);
9 printf("Enter number  3:\n"); S(C, 28)=(1,2,3,4,5,6,7,8,9,10,11,19,20,21,22,26,27,28)
10 scanf("%f", &C);
11 if(A>B) {  /*do nothing*/
18 }
19 else   {
20 if(C>B) {
21 printf("The largest number is: %f\n",C);
22 }
26 }
27 getch();
28 }
Slice Based Testing
S. No Slice Paths A B C Expected
output
1 S(A, 6) 1,2,3,4,5,6,28 9
1,2,3,4,5,6,7,8,9,10,11,12,
2 S(A, 13) 13,14,18,27,28 9 8 7 9

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

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

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

Slice Based Testing


S. No Slice Paths A B C Expected
output
6 S(B, 28) 1,2,3,4,5,6,7,8,9,10,11,19,
20,23,24,25,26,27,28 7 9 8 9

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

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

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

1,2,3,4,5,6,7,8,9,10,11,19, 7 8 9 9
10 S(C, 28)
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.