Chapter 6 Path Testing :A White box techniques 322 235 Software Testing By Asst.Prof.Dr.Wararat Songpan(Rungworawut) Department of Computer Science, Faculty of Science, Khon Kaen University 1 Level of Testing (Waterfall model) User Acceptance Testing Black Box (BVT, EC, DT) Requirements & Specification Design test scripts/test cases System Testing Execute Preliminary Design Design Integration Testing Execute White Box (Path Testing) & Black box Detailed Coding Design Coding Unit Testing Execute test scripts/test cases Path Testing • Path testing is a Structural Testing method (White box) that involves using the source code of a program to attempt to find every possible executable path. • The idea is that are able to test each individual path from source code is as many way as possible in order to maximize the coverage of each test case. • Therefore, we use knowledge of the source code to define the test cases and to examine outputs. • Test cases derived to exercise the basis set are guaranteed to execute every statement in the program at least one time during testing 3 Flow Graph • Given a program written in an imperative programming language, its program graph is a directed graph in which nodes are statement fragments, and edges represent flow of control • It may be called “Control Flow Graph” 4 Flow chart & Flow Graph Flow Chart Flow Graph 0 0 1 1 2 2 3 3 4 6 7 8 6 5 4 7 8 5 9 9 11 10 11 10 5 Flow Graph Notation Notation Description A circle in a graph represents a node, which stands for a sequence of one or more procedural statements A node containing a simple conditional expression is referred to as a predicate node which has two edges leading out from it (True and False) An edge, or a link, is a an arrow representing flow of control in a specific direction - An edge must start and terminate at a node - An edge does not intersect or cross over another edge 322 235 การทดสอบซอฟต์แวร์ 6 Flow Graph Example(1) 2 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Program ‘Simple Subtraction’ Input(x,y) Output (x) Output(y) If x> y then Do x-y = z Else y-x = z EndIf Output(z) Output “End Program” 3 4 5 7 6 8 9 322 235 การทดสอบซอฟต์แวร์ 10 7 Flow Graphs consist of 2 • A decision node is a program point at which the control can diverge. • (e.g., if and case statements) 3 4 5 N Y Y 7 6 8 N 9 Switch case While Loop Until Loop 10 8 Flow Graphs consist of 2 • A junction node is a program point where the control flow can merge. • (e.g., end if , end loop, goto label) 3 4 5 7 6 Goto Connector 8 9 10 9 Flow Graphs consist of 2 • A sequence node is a sequence of program statements uninterrupted by either decisions of junction. • (i.e. straight-line code) Sequence 3 4 5 7 6 8 9 322 235 การทดสอบซอฟต์แวร์ 10 10 Flow Graph Example(2) 1 1. scanf(“%d %d”,&x, &y); 2. If (y<0) 3. pow = -y; else 4. pow = y; 5. Z = 1.0 6. While (pow != 0) { 7. z = z*x; 8. pow = pow -1; } 9. If (y <0) 10. z = 1.0 /z; 11. printf(“%f”,z); 2 4 3 5 6 7 8 9 11 10 11 What is Path? • A path through a program is a sequence of statements that starts at an entry, junctions, sequence, or decision and ends. • A path may go through several junctions, sequences, or decisions, on or more times. • Paths consist of segments that has smallest segment is a link between 2 nodes. 322 235 การทดสอบซอฟต์แวร์ 12 What is Path? 2 • For example: Path1 = 2-3-4-5-6-8-9-10 3 4 5 7 6 8 9 10 13 What is Path? 2 • For example: Path2 = 2-3-4-5-7-8-9-10 3 4 5 7 6 8 9 10 14 Path Testing Strategies • Statement Testing 1 • a • Branch Testing 2 b T 100% statement / node coverage F c 3 • Path Testing 4 d e 5 f T Fg 6 7 h o 100% branch/ link coverage o 100% path coverage i 8 j 9 15 Path Testing Strategies • Statement Testing 1 • a • Branch Testing 2 b T 100% statement / node coverage F c 3 • Path Testing 4 d e 5 f T Fg 6 7 h o 100% branch/ link coverage o 100% path coverage i 8 j 9 16 Path Testing Strategies • Statement Testing 1 • a • Branch Testing 2 b T 100% statement / node coverage F c 3 • Path Testing 4 d e 5 f T Fg 6 7 h i 8 o 100% branch/ link coverage o 100% path coverage Statement Testing < Branch Testing < Path Testing j 9 17 Path Testing Strategies • Statement Testing 1 • a • Branch Testing 2 b T 100% statement / node coverage F c 3 • Path Testing 4 d e 5 f T Fg 6 7 h i 8 o 100% branch/ link coverage o 100% path coverage Statement Testing < Branch Testing < Path Testing j 9 18 Path Testing Strategies • Statement Testing 1 • a • Branch Testing 2 b T 100% statement / node coverage F c 3 • Path Testing 4 d e 5 f T Fg 6 7 h i 8 o 100% branch/ link coverage o 100% path coverage Statement Testing < Branch Testing < Path Testing j 9 19 Path Testing Strategies • Statement Testing 1 • a • Branch Testing 2 b T 100% statement / node coverage F c 3 • Path Testing 4 d e 5 f T Fg 6 7 h i 8 o 100% branch/ link coverage o 100% path coverage Statement Testing < Branch Testing < Path Testing j 9 20 A Coverage Table Decisions 1 a 2 b c T F 3 4 d e 5 f T F g 6 7 h i 8 j 9 21 322 235 Process-Link Paths 2 5 a 1-2-3-5-6-89 (a-b-d-f-h-j) T T 1-2-4-5-7-89 (a-c-e-g-i-j) F F 1-2-3-5-7-89 (a-b-d-g-i-j) T F 1-2-4-5-6-89 (a-c-e-f-h-j) F T การทดสอบซอฟต์แวร์ b c d e f g h i j 21 Example Flow Graph 1. Program Triangle 2. Dim a, b,c As Integer 3. Dim IsTriangle As Boolean 4 4. Output ( “enter a,b, and c integers”) 5. Input (a,b,c) 6. Output (“side 1 is”, a) 7. Output (“side 2 is”, b) 8. Output (”side 3 is”, c) 9. If (a<b+c) AND (b<a+c) And (c<b+a) 10. then IsTriangle = True 11. else IsTriangle = False 12. endif 5 6 T เป็ น สามเหลีย่ ม 7 9 8 F 10 ไม่เป็ น สามเหลีย่ ม 11 12 F Flow Graph 13. If IsTriangle 14. then if (a=b) AND (b=c) 15. then Output (“equilateral”) 16. else if (a != b) AND (a != b) AND (b != c) 17. then Output ( “Scalene”) 18. else Output (“Isosceles”) 19. endif 20. endif 21. else Output (“not a triangle”) 22. endif 23. end Triangle2 ไม่เป็ น สามเหลีย่ ม 21 13 T T 14 F 15 16 T 17 สามเหลีย่ ม ด้านเท่า 20 F 18 19 22 23 สามเหลีย่ ม ด้านไม่เท่า สามเหลีย่ ม หน้าจัว่ 22 Basis Path Testing 4 • Select Path is shortest or simple path • For example: 5 6 7 8 9 10 11 12 13 4-5-6-7-8-9-11-12-13-21-22-23 21 14 15 16 17 20 18 19 22 23 23 Test Case for Path Coverage 4-5-6-7-8-9-11-12-13-21-22-23 4-5-6-7-8-9-10-12-13-14-15-20-22-23 4-5-6-7-8-9-10-12-13-14-16-17-19-20-22-23 4-5-6-7-8-9-10-12-13-14-16-18-19-20-22-23 Path Decision 9 13 14 F F T T T T T F T T T Test case 16 Expected Results a b c 100 100 200 Not A triangle 100 100 100 Equilateral T 100 50 60 Scalene F 100 100 50 Isosceles 24 DD-Paths • It stand for Decision-to-Decision path in a directed graph. • A path are consists of the initial and nodes and interior node has indegree = 1 and outdegree = 1 indegree =1 outdegree =1 25 DD-Paths Characteristic of DD-Path has 5 cases: • • • • • Case 1: Single node with indeg =0 Case 2: Single node with outdeg = 0 Case 3: Single node with indeg >= 2 or outdeg >=2 Case 4: Single node with indeg = 1 and outdeg =1 Case 5: Maximum chain of length >=1 26 322 235 การทดสอบซอฟต์แวร์ 26 Condensation of Code to Table then to Flow Graph code statement 1. Program Triangle 2. Dim a, b,c As Integer 3. Dim IsTriangle As Boolean 4. Output ( “enter a,b, and c integers”) 5. Input (a,b,c) 6. Output (“side 1 is”, a) 7. Output (“side 2 is”, b) 8. Output (”side 3 is”, c) 9. If (a<b+c) AND (b<a+c) And (c<b+a) 10. then IsTriangle = True 11. else IsTriangle = False 12. endif Def of DD-paths on 13. If IsTriangle 14. then if (a=b) AND (b=c) 15. then Output (“equilateral”) 16. else if (a NE b) AND (a NE b) AND (b NE c) 17. then Output ( “Scalene”) 18. else Output (“Isosceles”) 19. endif 20. endif 21. else Output (“not a triangle”) 22. endif 23. end Triangle2 Path/node name DD-path Case Skip 1- 3 (or w/4) 4 5–8 first A 1 5 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 B C D E F H I J K L M N G O last 3 4 4 3 3 3 4 3 4 4 3 3 4 3 2 DD-Path First 4 5 6 7 8 A 9 B 10 11 C D 12 E 13 21 F 14 G 15 H 16 I 17 J 18 K 20 L 19 N M 22 O 23 Last 28 Path Analysis • What is path analysis? o Analyzes the number of paths that exist in the system o Facilitates the decision process of how many paths to include in the test 29 Path Analysis: Cyclomatic complexity measure (CFC) A CFC can be calculated by B V(G) = e-n+2 e : the number of edges n : the number of nodes Example: = 10-7+2 = 5 D T F E T C F F G 30 Path Analysis: Cyclomatic complexity measure (CFC) • If flow graph has link between sink node(G) to source node(A) which is called a strongly connected graph. A V(G) = e-n+1 e : the number of edges n : the number of nodes Example: 11-7+1 = 5 B D F T E T C F F G 31 How to select path • Independent Path • McCabe’s Baseline 322 235 การทดสอบซอฟต์แวร์ 32 Independent Path • Independent program paths an independent path is any path through the program that introduces at least one new set of processing link, statements or a new condition. • No count on traverse edge between sink node-G to source node-A o o o o o P1: A-B-C-G P2: A-B-C-B-C-G P3: A-B-E-F-G P4: A-D-E-F-G P5: A-D-F-G A B D T F E T C F F G 33 Independent Path Problem of Independent path o o o o o o o P1: A-B-C-G P2: A-B-C-B-C-G P3: A-B-E-F-G P4: A-D-E-F-G P5: A-D-F-G Ex1: A-B-C-B-E-F-G Ex2: A-B-C-B-C-B-C-G A B D T F E T C F F G 34 Independent Path • example2 V(G) = e-n+2 = 11-9+2 =4 A B C D I G E P1: A-I P2: A-B-C-D-F-H-A-I P3: A-B-C-E-F-H-A-I P4: A-B-G-H-A-I Is the path A-B-G-H-A-B-C-D-F-H-A-I and independent path? F H 35 McCabe’s Baseline To determine a set of basis paths, 1. Pick a "baseline" path that corresponds to normal execution. (The baseline should have as many decisions as possible.) 2. To get succeeding basis paths, retrace the baseline until you reach a decision node. "Flip" the decision (take another alternative) and continue as much of the baseline as possible. 3. Repeat this until all decisions have been flipped. When you reach V(G) basis paths, you're done. 4. If there aren't enough decisions in the first baseline path, find a second baseline and repeat steps 2 and 3. 36 McCabe’s Baseline • • • • • P1: A-B-C-B-E-F-G P2: A-B-E-F-G P3: A-B-C-G P4: A-D-E-F-G P5: A-D-F-G A B D T F E T C F F G 37 McCabe’s Path of Triangle Program First McCabe Paths Expected Results Original P1: First-A-B-C-E-F-H-J-KM-N-O-Last Scalene P2: First-A-B-D-E-F-H-J-KM-N-O-Last Infeasible path Flip P1 at F P3: First-A-B-C-E-F-G-OLast Infeasible path E Flip P1 at H P4: First-A-B-C-E-F-H-I-NO-Last Equilateral F Flip P1 at J P5: First-A-B-C-E-F-H-J-L-MN-O-Last Isosceles Flip P1 at B A ไม่เป็ น สามเหลีย่ ม B เป็ น สามเหลีย่ ม ไม่เป็ น สามเหลีย่ ม C D If IsTriangle G H I J K สามเหลีย่ ม ด้านเท่า N L M O Last สามเหลีย่ ม ด้านไม่เท่า สามเหลีย่ ม หน้าจัว่ 38 McCabe’s Path • Weakness of McCabe’s Path may occur “infeasible path” which means no found test case design to match with the path. McCabe Paths Expected Results P1 Original P1: First-A-B-C-E-F-H-J-K-M-N-OLast Scalene P6(from P2 and P3) New P6: First-A-B-D-E-F-G-O-Last Not a Triangle P4 Flip P1 at H P4: First-A-B-C-E-F-H-I-N-O-Last Equilateral P5 Flip P1 at J P5: First-A-B-C-E-F-H-J-L-M-N-OLast Isosceles 39 From path analysis to test case design Test Case From Path a b c Expected Results 1 P1 P6 P4 P5 3 4 5 3 4 1 5 2 5 2 5 2 Scalene 2 3 4 Not a Triangle Equilateral Isosceles 40 Steps of path testing • Deriving Test Cases 1. Using the design or code, draw the corresponding flow graph. 2. Determine the cyclomatic complexity of the flow graph. 3. determine a set of path by basis/independent/McCabe’s paths. 4. Prepare test cases that will force execution of each path in the basis set. 41 Path Testing Example public double calculate(int amount) { 1. double rushCharge = 0; if (nextday.equals("yes") ) { 2. rushCharge = 14.50; } 3 double tax = amount * .0725; 3 if (amount >= 1000) { 4. shipcharge = amount * .06 + rushCharge; } 5. else if (amount >= 200) { 6. shipcharge = amount * .08 + rushCharge; } 7. else if (amount >= 100) { 8. shipcharge = 13.25 + rushCharge; } 9. else if (amount >= 50) { 10. shipcharge = 9.95 + rushCharge; } 11. else if (amount >= 25) { 12. shipcharge = 7.25 + rushCharge; } else { 13. shipcharge = 5.25 + rushCharge; } 14. total = amount + tax + shipcharge; 15. return total; } //end calculate 42 Path Testing Example • Here is a drawing of the flowgraph. 1 3 2 4 5 6 7 8 9 10 11 12 13 14 43 Path Testing Example • Step 2: Determine the cyclomatic complexity of the flow graph. • V(G) = E - N + 2 = 19 - 14 + 2 = 7 44 Path Testing Example (McCabe’s Path ) • Step 3: Determine the basis set of paths using McCabe’s Path Path 1: 1 - 2 - 3 - 5 - 7 - 9 - 11 - 13 - 14 Path 2: 1 - 3 - 5 - 7 - 9 - 11 - 13 - 14 Path 3: 1 - 3 - 4 - 14 Path 4: 1 - 3 - 5 - 6 - 14 Path 5: 1 - 3 - 5 - 7 - 8 - 14 Path 6: 1 - 3 - 5 - 7 - 9 - 10 - 14 Path 7: 1 - 3 - 5 - 7 - 9 - 11 - 12 - 14 45 Path Testing Example (McCabe’s Path) • step 4: Prepare test cases that force execution of each path with McCabe’s Path. Path Next day Amount Expected Results P1 yes 10 30.475 P2 No 10 15.975 P3 No 1500 1713.25 P4 No 300 345.75 P5 No 150 174.125 P6 No 75 90.3875 P7 No 30 39.425 46 Path Testing Example (basis path) 1 • Determine the basis set of paths using basis path P1: 1-3-4-14 P2: 1-2-3-4-14 P3: 1-2-3-5-6-14 P4: 1-2-3-5-7-8-14 P5: 1-2-3-5-7-9-10-14 P6: 1-2-3-5-7-9-11-12-14 P7: 1-2-3-5-7-9-11-13-14 3 2 4 5 6 7 8 9 10 11 12 13 14 47 Path Testing Example (Independent path) • Determine the basis set of paths using independent path P1: 1-3-5-6-14 P2: 1-2-5-6-14 P2: 1-2-3-4-14 P3: 1-2-3-5-7-8-14 P4: 1-2-3-5-7-9-10-14 P5: 1-2-3-5-7-9-11-12-14 P7: 1-2-3-5-7-9-11-13-14 1 3 2 4 5 6 7 8 9 10 11 12 13 14 48
© Copyright 2024 Paperzz