1 / 44

Chapter 6 Path Testing 322 235 Software Testing

Chapter 6 Path Testing 322 235 Software Testing. By Wararat Songpan ( Rungworawut ),PH.D. Department of Computer Science, Faculty of Science, Khon Kaen University. Path Testing.

Télécharger la présentation

Chapter 6 Path Testing 322 235 Software Testing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6 Path Testing 322 235 Software Testing By WararatSongpan(Rungworawut),PH.D. Department of Computer Science, Faculty of Science, KhonKaen University

  2. Path Testing • Path testing is a Structural Testing method 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 individualpath 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 6 6 4 4 7 8 5 7 8 5 9 9 11 10 11 10

  5. Flow Graph Notation 322 235 การทดสอบซอฟต์แวร์

  6. Flow Graph Example(1) 2 • 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 10 322 235 การทดสอบซอฟต์แวร์

  7. Flow Graphs consist of 2 • A decision is a program point at which the control can diverge. • (e.g., if and case statements) 3 4 5 7 6 Y N Y 8 N 9 Switch case Until Loop While Loop 10

  8. Flow Graphs consist of 2 • A junction is a program point where the control flow can merge. • (e.g., end if , end loop, goto label) 3 4 5 7 6 Goto 8 Connector 9 10

  9. Flow Graphs consist of 2 • A process block is a sequence of program statements uninterrupted by either decisions of junction. • (i.e. straight-line code) 3 4 5 Sequence 7 6 8 9 10 322 235 การทดสอบซอฟต์แวร์

  10. Flow Graph Example(2) 1 • scanf(“%d %d”,&x, &y); • If (y<0) • pow = -y; else 4. pow = y; • Z = 1.0 • While (pow != 0) { • z = z*x; • pow = pow -1; } • If (y <0) • z = 1.0 /z; • printf(“%f”,z); 2 4 3 5 6 7 8 9 10 11

  11. What is Path? • A path through a program is a sequence of statements that starts at an entry, junctions, or decision and ends. • A path may go through several junctions, processes, 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 12

  13. What is Path? 2 • For example: Path2 = 2-3-4-5-7-8-9-10 3 4 5 7 6 8 9 10 13

  14. Path Testing Strategies • StatementTesting • 100%statement / nodecoverage • Branch Testing • 100% branch/ link coverage • Path Testing • 100%path coverage 1 a 2 b c F T 3 4 d e 5 T F f g 6 7 h i 8 j 9

  15. Path Testing Strategies • StatementTesting • 100%statement / nodecoverage • Branch Testing • 100% branch/ link coverage • Path Testing • 100%path coverage 1 a 2 b c F T 3 4 d e 5 T F f g 6 7 h i 8 j 9

  16. Path Testing Strategies • StatementTesting • 100%statement / nodecoverage • Branch Testing • 100% branch/ link coverage • Path Testing • 100%path coverage 1 a 2 b c F T 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

  17. Path Testing Strategies • StatementTesting • 100%statement / nodecoverage • Branch Testing • 100% branch/ link coverage • Path Testing • 100%path coverage 1 a 2 b c F T 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

  18. Path Testing Strategies • StatementTesting • 100%statement / nodecoverage • Branch Testing • 100% branch/ link coverage • Path Testing • 100%path coverage 1 a 2 b c F T 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

  19. Path Testing Strategies • StatementTesting • 100%statement / nodecoverage • Branch Testing • 100% branch/ link coverage • Path Testing • 100%path coverage 1 a 2 b c F T 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

  20. A Coverage Table 1 a 2 b c T F 3 4 d e 5 f g T F 6 7 h i 8 j 9 322 235 การทดสอบซอฟต์แวร์ 20

  21. Exmple Flow Graph 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 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 4 5 6 7 8 9 Flow Graph 23 22 21 20 19 18 10 16 15 11 13 12 17 14

  22. Basis Path Testing 4 5 6 7 8 • Select Pathis shortest or simple path • For example: 4-5-6-7-8-9-10-12-13-21-22-23 9 23 14 10 22 12 13 11 18 16 17 19 20 21 15 322 235 การทดสอบซอฟต์แวร์ 22

  23. Test Case for Path Coverage •  4-5-6-7-8-9-10-12-13-21-22-23 • 4-5-6-7-8-9-11-12-13-14-15-20-22-23 • 4-5-6-7-8-9-11-12-13-14-16-17-19-20-22-23 • 4-5-6-7-8-9-11-12-13-14-16-18-19-20-22-23

  24. DD-Paths • It stand for Decision-to-Decision pathin 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 withoutdeg = 0 • Case 3:Single node withindeg >= 2 oroutdeg >=2 • Case 4:Single node withindeg = 1 andoutdeg =1 • Case 5:Maximum chain of length >=1 322 235 การทดสอบซอฟต์แวร์ 25

  26. Condensation of Code to Table then to Flow Graph Path/node name DD-path Case 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 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 Skip 1- 3 (or w/4) 4 first 1 5 – 8 A 5 9 B 3 10 C 4 11 D 4 12 E 3 13 F 3 14 H 3 15 I 4 16 J 3 17 K 4 18 L 4 19 M 3 20 N 3 21 G 4 22 O 3 23 last 2 Def of DD-paths on

  27. DD-Path 4 5 6 7 8 A 9 B First Last O K D E F H I J L M N G 22 19 13 17 21 20 11 10 12 18 14 15 16 C 23

  28. Path Analysis • What is path analysis? • Analyzes the number of paths that exist in the system • Facilitates the decision process of how many paths to include in the test

  29. Path Analysis: Cyclomatic complexity measure(CFC) CFC can be calculated by V(G) = e-n+2 e : the number of edges n : the number of nodes Example: = 10-7+2 = 5 A B D T F E F T C F G

  30. Path Analysis: Cyclomatic complexity measure(CFC) • If flow graph has link between sink node(G) to source node(A) which is calledastrongly connected graph. V(G) = e-n+1 e : the number of edges n : the number of nodes Example: 11-7+1 = 5 A B D F T E T F C F G 322 235 การทดสอบซอฟต์แวร์ 30

  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 statements or a new condition. • Cyclomatic complexity is a software metric that provides a quantitative measure of the logical complexity if a program • No count on traverse edge between sink node-G to source node-A • 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 F T C F G

  33. Independent Path Problem of Independent path • 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 F T C F G

  34. 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.

  35. McCabe’s Baseline • P1: A-B-C-B-E-F-G • P2: A-D-E-F-G • P3: A-D-F-G • P4: A-B-E-F-G • P5: A-B-C-G A B D T F E F T C F G

  36. McCabe’s Path of Triangle Program A B First Last K O G N M L F I H D E C J

  37. McCabe’s Path • Weakness of McCabe’s Path may occur “infeasible path” which means no found test case design to match with the path.

  38. From path analysis to test case design

  39. Steps of path testing • Deriving Test Cases • Using the design or code, draw the corresponding flow graph. • Determine the cyclomatic complexity of the flow graph. • determine a set of path by basis/independent/McCabe’s paths. • Prepare test cases that will force execution of each path in the basis set.

  40. Basis 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; 14. return total; } //end calculate

  41. Basis Path Testing Example 1 • Here is a drawing of the flowgraph. 2 3 4 6 5 7 8 10 9 12 11 13 14

  42. Basis Path Testing Example • Step 2: Determine the cyclomatic complexity of the flow graph. • V(G) = E - N + 2         = 19 - 14 + 2         =  7

  43. Basis Path Testing Example • Step 3: Determine the basis set of independent paths. • Path 1:  1 - 2 - 3 - 5 - 7 - 9 - 11 - 13 - 14 Path 2:  1 - 3 - 4 - 14 Path 3:  1 - 3 - 5 - 6 - 14 Path 4:  1 - 3 - 5 - 7 - 8 - 14 Path 5:  1 - 3 - 5 - 7 - 9 - 10 - 14 Path 6:  1 - 3 - 5 - 7 - 9 - 11 - 12 - 14 Path 7:  1 - 3 - 5 - 7 - 9 - 11 - 13 - 14

  44. Basis Path Testing Example • step 4: Prepare test cases that force execution of each path in the basis set.

More Related