SlideShare uma empresa Scribd logo
1 de 18
Software Testing
CHAPTER # 9: SLICE-BASED TESTING
Slice Based Testing
Program slicing was introduced by Mark Weiser [WEIS84] where we prepare various subsets
(called slices) of a program with respect to its variables and their selected locations in the
program.
Each variable with one of its location will give us a program slice.
A large program may have many smaller programs (its slices), each constructed for different
variable subsets.
The slices are typically simpler than the original program, thereby simplifying the process of
testing of the program.
Slice Based Testing
“Program slicing is a technique for restricting the behaviour of a program to some specified
subset of interest. A slice S( , n) of program P on variable , or set of variables, at statement n
yields the portions of the program that contributed to the value of just before statement n is
executed. S ( , n) is called a slicing criteria. Slices can be computed automatically on source
programs by analyzing data flow. A program slice has the added advantage of being an executable
program.” [KEIT91]
Slices are smaller than the original program and may be executed independently. Only two things
are important here, variable and its selected location in the program.
Slice Based Testing
Slice: Given a program P and a set V of variables in P, a slice on the variable set V at statement
n, written S(V, n), is the set of all statement fragments in P that contribute to the values of
variables in V at node n.
Backward and Forward Program Slice
Backward Slice: Backward slices refer to statement fragments that contribute to the value of v at
statement n.
Forward Slice: Forward slices refer to all the program statements that are affected by the value of
v and statement n.
Program Slice
Static slice S(v, n) consists of all the statements in a program that determine the value of
variable v at statement n,independent of values used in the statements.
Dynamic slices refer to execution-time execution of portions of a static slice with specific values
of all variables in S(v, n).
Static and Dynamic Slice
1. int z=10;
2. int n;
3. cin>>n;
4. int sum=0;
5. if (n>10)
6. sum = sum + n;
7. else
8. sum = sum – n;
9. cout <<sum;
Static slice for variable
sum
2,3,4,5,6,7,8,9
int n;
cin>>n;
int sum=0;
if (n>10)
sum = sum + n;
else
sum = sum – n;
cout <<sum;
Dynamic slice for
variable sum when n=
15
2,3,4,5,6,9
int n;
cin>>n;
int sum=0;
if (n>10)
sum = sum + n;
cout <<sum;
Program Slicing
Consider the program given below:
1. void main ( )
2. {
3. int a, b, c, d, e;
4. cout<<“Enter the values of a, b and
c”<<endl;
5. cin>>a >>b >>c;
6. d = a+b;
7. e = b+c:
8. cout<<d;
9. cout<<e;
10. }
Slice on criterion S (e, 10) = (1, 2, 3, 4, 5, 7, 9, 10)
1. void main ( )
2. {
3. int a, b, c, d, e;
4. cout<<“Enter the values of a, b and
c”<<endl;
5. cin>>a >>b >>c;
7. e = b+c:
9. cout<<e;
10. }
Program Slicing
Slice on criterion S (e,7) = (1, 2, 3, 4, 5, 7,10)
1. void main ( )
2. {
3. int a, b, c, d, e;
4. cout<<“Enter the values of a, b and
c”<<endl;
5. cin>>a >>b >>c;
7. e = b+c:
10. }
Slice on criterion S (d,10) = (1, 2, 3, 4, 5, 6, 8, 10)
1. void main ( )
2. {
3. int a, b, c, d, e;
4. cout<<“Enter the values of a, b and
c”<<endl;
5. cin>>a >>b >>c;
6. d = a+b;
8. cout<<d;
10. }
Guidelines for Slicing
There are many variables in a program, but their usage may be different in different statements.
The following guidelines may be used for the creation of program slices.
 All statements where variables are defined and redefined should be considered.
 All statements where variables receive values externally should be considered.
 All statements where output of a variable is printed should be considered.
 All statements where some relevant output is printed should be considered.
 The status of all variables may be considered at the last statement of the program.
1. void main()
2. 2. {
3. double a,b,c;
4. double a1,a2,a3;
5. int valid=0;
6.
7. cout<<"Enter first side of the triangle:";
8. cin>>a;
9. cout<<"Enter second side of the triangle:";
10. cin>>b;
11. cout<<"Enter third side of the triangle:";
12. cin>>c;
/*Checks whether a triangle is valid or not*/
13.
if(a>0&&a<=100&&b>0&&b<=100&&c>0&&c<=100)
{
14. if((a+b)>c&&(b+c)>a&&(c+a)>b) {
15. valid=1;
16. }
17. else {
18. valid=-1;
19. }
20. }
21. if(valid==1) {
22. a1=(a*a+b*b)/(c*c);
23. a2=(b*b+c*c)/(a*a);
24. a3=(c*c+a*a)/(b*b);
25. if(a1<1||a2<1||a3<1) {
26. cout<<"Obtuse angled triangle";
27. }
28. else if(a1==1||a2==1||a3==1) {
29. cout<<"Right angled triangle";
30. }
31. else {
32. cout<<"Acute angled triangle";
33. }
34. }
35. else if(valid==-1) {
36. cout<<"nInvalid Triangle";
37. }
38. else {
39. cout<<"nInput Values are Out of Range";
40. }
41.
42. } //end of main
Program Slicing for Triangle problem
All statements where variables are defined and redefined should be considered.
 Variable valid is defined at line 5, and redefined at 15 and 18. we may create S(valid, 5),
S(valid, 15) and S(valid, 18) slices
All statements where variables receive values externally should be considered.
 variables ‘a’, ‘b’ and ‘c’ receive values externally at line 8, 10 and12 respectively. we may create
S(a, 8), S(b, 10) and S(c, 12) slices
All statements where output of a variable is printed should be considered.
All statements where some relevant output is printed should be considered.
 line 26, 29, 32, 36 and 39 are used for printing the classification of the triangle. We may create
S(a1, 26), S(a1, 29), S(a1, 32), S(valid, 36) and S(valid, 39) as slices
The status of all variables may be considered at the last statement of the program.
 line 42 is the last statement of the program. We may create S(a1, 42), S(a2, 42), S(a3, 42),
S(valid, 42), S(a, 42), S(b,42) and S(c, 42) as slices.
Program Slicing for Triangle problem
There are seven variables ‘a’, ‘b’, ‘c’, ‘a1’, ‘a2’, ‘a3’ and ‘valid’ in the program.
We may create many slices as given below:
1. S (a, 8) = {1–8, 42}
2. S (b, 10) = {1–6, 9, 10, 42}
3. S (c, 12) = {1–6, 11, 12, 42}
4. S (a1, 22) = {1–16, 20–22, 34, 42}
5. S (a1, 26) = {1–16, 20–22, 25–27, 34, 41, 42}
6. S (a1, 29) = {1–16, 20–22, 25, 27–31, 33, 34, 41, 42}
7. S (a1, 32) = {1–16, 20–22, 25, 27, 28, 30–34, 41, 42}
8. S (a2, 23) = {1–16, 20, 21,23, 34, 42}
9. S (a2, 26) = {1–16, 20, 21, 23, 25–27, 34, 41, 42}
10.S (a2, 29) = {1–16, 20, 21, 23, 25, 27–31, 33, 34, 41, 42}
11.S (a2, 32) = {1–16, 20, 21, 23, 25, 27, 28, 30–34, 41, 42}
Program Slicing for Triangle problem
12.S (a3, 26) = {1–16, 20, 21, 24–27, 34, 41, 42}
13.S (a3, 29) = {1–16, 20, 21, 24, 25, 27–31, 33, 34, 41,42}
14.S (a3, 32) = {1–16, 20, 21, 24, 25, 27, 28, 30–34, 41, 42}
15.S (valid, 5) = {1–5, 42}
16.S (valid, 15) = {1–16, 20, 42}
17.S (valid, 18) = {1–14, 16–20, 42}
18.S (valid, 36) = {1–14, 16–20, 21, 34–38, 40–42}
19.S (valid, 39) = {1–13, 20, 21, 34, 35, 37–42}
Test Cases
Slice Path a b c Expected Output
1 S(a, 8)/S(a,42) 1-8, 42 20 No Output
2 S(b, 10)/S(b,42) 1-6, 9, 10, 42 20 No Output
3 S(c, 12)/S(c,42) 1-6, 11, 12, 42 20 No Output
4 S(a1, 22) 1–16, 20–22, 34, 42 30 20 40 No output
5 S(a1, 26) 1–16, 20–22, 25–27, 34, 41, 42 30 20 40 Obtuse angled triangle
6 S(a1, 29) 1–16, 20–22, 25, 27–31, 33, 34, 41, 42 30 40 50 Right angled triangle
7 S(a1, 32) 1–16, 20–22, 25, 27, 28, 30–34, 41, 42 50 60 40 Acute angled triangle
8 S(a1, 42) 1–16, 20–22, 34, 42 30 20 40 No output
9 S(a2, 23) 1–16, 20, 21, 23, 34, 42 30 20 40 No output
10 S(a2, 26) 1–16, 20, 21, 23, 25–27, 34, 41, 42 40 30 20 Obtuse angled triangle
11 S(a2, 29) 1–16, 20, 21, 23, 25, 27–31, 33, 34, 41, 42 50 40 30 Right angled triangle
Test Cases
Slice Path a b c Expected Output
12 S(a2, 32) 1–16, 20, 21, 23, 25, 27, 28, 30–34, 41, 42 40 50 60 Acute angled triangle
13 S(a2, 42) 1–16, 20, 21, 23, 34, 42 30 20 40 No output
14 S(a3, 24) 1–16, 20, 21, 24, 34, 42 30 20 40 No output
15 S(a3, 26) 1–16, 20, 21, 24–27, 34, 41, 42 20 40 30 Obtuse angled triangle
16 S(a3, 29) 1–16, 20, 21, 24, 25, 27–31, 33, 34, 41, 42 40 50 30 Right angled triangle
17 S(a3, 32) 1–16, 20, 21, 24, 25, 27, 28, 30–34, 41, 42 50 40 60 Acute angled triangle
18 S(a3, 42) 1–16, 20, 21, 24, 34, 42 30 20 40 No output
19 S(valid,5) 1–2, 5, 42 No output
20 S(valid,15) 1–16, 20, 42 20 40 30 No output
21 S(valid,18) 1–14, 16–20, 42 30 10 15 No output
22 S(valid,36) 1–14, 16–20, 21, 34–38, 40–42 30 10 15 Invalid triangle
Test Cases
Slice Path a b c Expected Output
23 S(valid,39) 1–13, 20, 21, 34, 35, 37–42 102 -1 6 Input values out of range
24 S(valid,42) 1–14, 16–20, 42 30 10 15 No output
References
Software Testing: A Craftsman’s Approach, by Paul C. Jorgensen & Byron DeVries 5th Edition
Software Testing, by Yogesh Singh

Mais conteúdo relacionado

Semelhante a Slice-Based Software Testing Techniques

MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfahmed8651
 
Scalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving GraphsScalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving GraphsNicolas Kourtellis
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Prosanta Ghosh
 
Bba 3274 qm week 6 part 1 regression models
Bba 3274 qm week 6 part 1 regression modelsBba 3274 qm week 6 part 1 regression models
Bba 3274 qm week 6 part 1 regression modelsStephen Ong
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answerRaajTech
 
Final Design Project - Memo (with GUI)
Final Design Project - Memo (with GUI)Final Design Project - Memo (with GUI)
Final Design Project - Memo (with GUI)Alex Larcheveque
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4Randa Elanwar
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordLakshmi Sarvani Videla
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4Kunihiko Saito
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_rRazzaqe
 
Barisan dan deret 1 bilingual
Barisan dan deret 1 bilingualBarisan dan deret 1 bilingual
Barisan dan deret 1 bilingualmentjirungkat
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in cBUBT
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysisVishal Singh
 

Semelhante a Slice-Based Software Testing Techniques (20)

MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 
Scalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving GraphsScalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving Graphs
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
 
Bba 3274 qm week 6 part 1 regression models
Bba 3274 qm week 6 part 1 regression modelsBba 3274 qm week 6 part 1 regression models
Bba 3274 qm week 6 part 1 regression models
 
White box testing
White box testingWhite box testing
White box testing
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
Final Design Project - Memo (with GUI)
Final Design Project - Memo (with GUI)Final Design Project - Memo (with GUI)
Final Design Project - Memo (with GUI)
 
Chapter 6 arrays part-1
Chapter 6   arrays part-1Chapter 6   arrays part-1
Chapter 6 arrays part-1
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_r
 
Barisan dan deret 1 bilingual
Barisan dan deret 1 bilingualBarisan dan deret 1 bilingual
Barisan dan deret 1 bilingual
 
Rsh qam11 ch04 ge
Rsh qam11 ch04 geRsh qam11 ch04 ge
Rsh qam11 ch04 ge
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
 
Laboratorio vibra
Laboratorio vibraLaboratorio vibra
Laboratorio vibra
 
Ch3
Ch3Ch3
Ch3
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 

Último

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Último (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

Slice-Based Software Testing Techniques

  • 1. Software Testing CHAPTER # 9: SLICE-BASED TESTING
  • 2. Slice Based Testing Program slicing was introduced by Mark Weiser [WEIS84] where we prepare various subsets (called slices) of a program with respect to its variables and their selected locations in the program. Each variable with one of its location will give us a program slice. A large program may have many smaller programs (its slices), each constructed for different variable subsets. The slices are typically simpler than the original program, thereby simplifying the process of testing of the program.
  • 3. Slice Based Testing “Program slicing is a technique for restricting the behaviour of a program to some specified subset of interest. A slice S( , n) of program P on variable , or set of variables, at statement n yields the portions of the program that contributed to the value of just before statement n is executed. S ( , n) is called a slicing criteria. Slices can be computed automatically on source programs by analyzing data flow. A program slice has the added advantage of being an executable program.” [KEIT91] Slices are smaller than the original program and may be executed independently. Only two things are important here, variable and its selected location in the program.
  • 4. Slice Based Testing Slice: Given a program P and a set V of variables in P, a slice on the variable set V at statement n, written S(V, n), is the set of all statement fragments in P that contribute to the values of variables in V at node n.
  • 5. Backward and Forward Program Slice Backward Slice: Backward slices refer to statement fragments that contribute to the value of v at statement n. Forward Slice: Forward slices refer to all the program statements that are affected by the value of v and statement n.
  • 6. Program Slice Static slice S(v, n) consists of all the statements in a program that determine the value of variable v at statement n,independent of values used in the statements. Dynamic slices refer to execution-time execution of portions of a static slice with specific values of all variables in S(v, n).
  • 7. Static and Dynamic Slice 1. int z=10; 2. int n; 3. cin>>n; 4. int sum=0; 5. if (n>10) 6. sum = sum + n; 7. else 8. sum = sum – n; 9. cout <<sum; Static slice for variable sum 2,3,4,5,6,7,8,9 int n; cin>>n; int sum=0; if (n>10) sum = sum + n; else sum = sum – n; cout <<sum; Dynamic slice for variable sum when n= 15 2,3,4,5,6,9 int n; cin>>n; int sum=0; if (n>10) sum = sum + n; cout <<sum;
  • 8. Program Slicing Consider the program given below: 1. void main ( ) 2. { 3. int a, b, c, d, e; 4. cout<<“Enter the values of a, b and c”<<endl; 5. cin>>a >>b >>c; 6. d = a+b; 7. e = b+c: 8. cout<<d; 9. cout<<e; 10. } Slice on criterion S (e, 10) = (1, 2, 3, 4, 5, 7, 9, 10) 1. void main ( ) 2. { 3. int a, b, c, d, e; 4. cout<<“Enter the values of a, b and c”<<endl; 5. cin>>a >>b >>c; 7. e = b+c: 9. cout<<e; 10. }
  • 9. Program Slicing Slice on criterion S (e,7) = (1, 2, 3, 4, 5, 7,10) 1. void main ( ) 2. { 3. int a, b, c, d, e; 4. cout<<“Enter the values of a, b and c”<<endl; 5. cin>>a >>b >>c; 7. e = b+c: 10. } Slice on criterion S (d,10) = (1, 2, 3, 4, 5, 6, 8, 10) 1. void main ( ) 2. { 3. int a, b, c, d, e; 4. cout<<“Enter the values of a, b and c”<<endl; 5. cin>>a >>b >>c; 6. d = a+b; 8. cout<<d; 10. }
  • 10. Guidelines for Slicing There are many variables in a program, but their usage may be different in different statements. The following guidelines may be used for the creation of program slices.  All statements where variables are defined and redefined should be considered.  All statements where variables receive values externally should be considered.  All statements where output of a variable is printed should be considered.  All statements where some relevant output is printed should be considered.  The status of all variables may be considered at the last statement of the program.
  • 11. 1. void main() 2. 2. { 3. double a,b,c; 4. double a1,a2,a3; 5. int valid=0; 6. 7. cout<<"Enter first side of the triangle:"; 8. cin>>a; 9. cout<<"Enter second side of the triangle:"; 10. cin>>b; 11. cout<<"Enter third side of the triangle:"; 12. cin>>c; /*Checks whether a triangle is valid or not*/ 13. if(a>0&&a<=100&&b>0&&b<=100&&c>0&&c<=100) { 14. if((a+b)>c&&(b+c)>a&&(c+a)>b) { 15. valid=1; 16. } 17. else { 18. valid=-1; 19. } 20. } 21. if(valid==1) { 22. a1=(a*a+b*b)/(c*c); 23. a2=(b*b+c*c)/(a*a); 24. a3=(c*c+a*a)/(b*b); 25. if(a1<1||a2<1||a3<1) { 26. cout<<"Obtuse angled triangle"; 27. } 28. else if(a1==1||a2==1||a3==1) { 29. cout<<"Right angled triangle"; 30. } 31. else { 32. cout<<"Acute angled triangle"; 33. } 34. } 35. else if(valid==-1) { 36. cout<<"nInvalid Triangle"; 37. } 38. else { 39. cout<<"nInput Values are Out of Range"; 40. } 41. 42. } //end of main
  • 12. Program Slicing for Triangle problem All statements where variables are defined and redefined should be considered.  Variable valid is defined at line 5, and redefined at 15 and 18. we may create S(valid, 5), S(valid, 15) and S(valid, 18) slices All statements where variables receive values externally should be considered.  variables ‘a’, ‘b’ and ‘c’ receive values externally at line 8, 10 and12 respectively. we may create S(a, 8), S(b, 10) and S(c, 12) slices All statements where output of a variable is printed should be considered. All statements where some relevant output is printed should be considered.  line 26, 29, 32, 36 and 39 are used for printing the classification of the triangle. We may create S(a1, 26), S(a1, 29), S(a1, 32), S(valid, 36) and S(valid, 39) as slices The status of all variables may be considered at the last statement of the program.  line 42 is the last statement of the program. We may create S(a1, 42), S(a2, 42), S(a3, 42), S(valid, 42), S(a, 42), S(b,42) and S(c, 42) as slices.
  • 13. Program Slicing for Triangle problem There are seven variables ‘a’, ‘b’, ‘c’, ‘a1’, ‘a2’, ‘a3’ and ‘valid’ in the program. We may create many slices as given below: 1. S (a, 8) = {1–8, 42} 2. S (b, 10) = {1–6, 9, 10, 42} 3. S (c, 12) = {1–6, 11, 12, 42} 4. S (a1, 22) = {1–16, 20–22, 34, 42} 5. S (a1, 26) = {1–16, 20–22, 25–27, 34, 41, 42} 6. S (a1, 29) = {1–16, 20–22, 25, 27–31, 33, 34, 41, 42} 7. S (a1, 32) = {1–16, 20–22, 25, 27, 28, 30–34, 41, 42} 8. S (a2, 23) = {1–16, 20, 21,23, 34, 42} 9. S (a2, 26) = {1–16, 20, 21, 23, 25–27, 34, 41, 42} 10.S (a2, 29) = {1–16, 20, 21, 23, 25, 27–31, 33, 34, 41, 42} 11.S (a2, 32) = {1–16, 20, 21, 23, 25, 27, 28, 30–34, 41, 42}
  • 14. Program Slicing for Triangle problem 12.S (a3, 26) = {1–16, 20, 21, 24–27, 34, 41, 42} 13.S (a3, 29) = {1–16, 20, 21, 24, 25, 27–31, 33, 34, 41,42} 14.S (a3, 32) = {1–16, 20, 21, 24, 25, 27, 28, 30–34, 41, 42} 15.S (valid, 5) = {1–5, 42} 16.S (valid, 15) = {1–16, 20, 42} 17.S (valid, 18) = {1–14, 16–20, 42} 18.S (valid, 36) = {1–14, 16–20, 21, 34–38, 40–42} 19.S (valid, 39) = {1–13, 20, 21, 34, 35, 37–42}
  • 15. Test Cases Slice Path a b c Expected Output 1 S(a, 8)/S(a,42) 1-8, 42 20 No Output 2 S(b, 10)/S(b,42) 1-6, 9, 10, 42 20 No Output 3 S(c, 12)/S(c,42) 1-6, 11, 12, 42 20 No Output 4 S(a1, 22) 1–16, 20–22, 34, 42 30 20 40 No output 5 S(a1, 26) 1–16, 20–22, 25–27, 34, 41, 42 30 20 40 Obtuse angled triangle 6 S(a1, 29) 1–16, 20–22, 25, 27–31, 33, 34, 41, 42 30 40 50 Right angled triangle 7 S(a1, 32) 1–16, 20–22, 25, 27, 28, 30–34, 41, 42 50 60 40 Acute angled triangle 8 S(a1, 42) 1–16, 20–22, 34, 42 30 20 40 No output 9 S(a2, 23) 1–16, 20, 21, 23, 34, 42 30 20 40 No output 10 S(a2, 26) 1–16, 20, 21, 23, 25–27, 34, 41, 42 40 30 20 Obtuse angled triangle 11 S(a2, 29) 1–16, 20, 21, 23, 25, 27–31, 33, 34, 41, 42 50 40 30 Right angled triangle
  • 16. Test Cases Slice Path a b c Expected Output 12 S(a2, 32) 1–16, 20, 21, 23, 25, 27, 28, 30–34, 41, 42 40 50 60 Acute angled triangle 13 S(a2, 42) 1–16, 20, 21, 23, 34, 42 30 20 40 No output 14 S(a3, 24) 1–16, 20, 21, 24, 34, 42 30 20 40 No output 15 S(a3, 26) 1–16, 20, 21, 24–27, 34, 41, 42 20 40 30 Obtuse angled triangle 16 S(a3, 29) 1–16, 20, 21, 24, 25, 27–31, 33, 34, 41, 42 40 50 30 Right angled triangle 17 S(a3, 32) 1–16, 20, 21, 24, 25, 27, 28, 30–34, 41, 42 50 40 60 Acute angled triangle 18 S(a3, 42) 1–16, 20, 21, 24, 34, 42 30 20 40 No output 19 S(valid,5) 1–2, 5, 42 No output 20 S(valid,15) 1–16, 20, 42 20 40 30 No output 21 S(valid,18) 1–14, 16–20, 42 30 10 15 No output 22 S(valid,36) 1–14, 16–20, 21, 34–38, 40–42 30 10 15 Invalid triangle
  • 17. Test Cases Slice Path a b c Expected Output 23 S(valid,39) 1–13, 20, 21, 34, 35, 37–42 102 -1 6 Input values out of range 24 S(valid,42) 1–14, 16–20, 42 30 10 15 No output
  • 18. References Software Testing: A Craftsman’s Approach, by Paul C. Jorgensen & Byron DeVries 5th Edition Software Testing, by Yogesh Singh