Anda di halaman 1dari 5

Slice Based Testing

A slice S(v,n) of program P on


STRUCTURAL TESTING 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

Slice Based Testing Slice Based Testing


� Introduced by Mark Weiser. GUIDELINES FOR SLICING
� Prepares various subsets �All statements where variables are defined and
(called slices) of program with redefined should be considered.
respect to its variables and
�All statements where variables are receiving
their selected locations in the
values externally should be considered.
program.
�All statements where output of a variable is printed
� Slices are simpler than the
should be considered.
original program and simplify
the process of testing of the
program.
Slice Based Testing Slice Based Testing
GUIDELINES FOR SLICING S(c,5) S(c,3)
�All the statements where relevant output is printed 1. a=3; 2. b=6;
should be considered.
2. b=6; 3. c=b2;
�The status of all variables may be considered at
5. c=a+b;
last statement of the program.

Slice Based Testing Slice Based Testing


Consider the following portion of a program: Consider the following program. Create slices based on slicing criterion.
1. void main()
1.a=3; 2. {
3. int a,b,c,d,e;
2.b=6;
4. printf(“Enter the values of a,b, and c\n”);
3.c=b2; 5. scanf(“%d %d %d”,&a,&b,&c);
6. d=a+b;
4.d=a2+b2;
7. e=b+c;
5.c=a+b; 8. printf(“%d”,d);
9. printf(“%d”,e);
10.}
Slice Based Testing Slice Based Testing
1. S(A,6)=(1,2,3,4,5,6,28)
Consider the program to find largest number
2. S(A, 13)=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,27,28)
amongst three numbers. Create slices on the
variables and generate test cases. 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 Slice Based Testing


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

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


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

Anda mungkin juga menyukai