Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 Path Testing Software Testing

Similar presentations


Presentation on theme: "Chapter 6 Path Testing Software Testing"— Presentation transcript:

1 Chapter 6 Path Testing 322 235 Software Testing
By Wararat Songpan(Rungworawut),PH.D. Department of Computer Science, Faculty of Science, Khon Kaen 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 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 1 1 2 2 3 3 6 4 6 4 7 8 5 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 การทดสอบซอฟต์แวร์

6 Flow Graph Example(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 6 7 8 9 10 การทดสอบซอฟต์แวร์

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 6 7 N Y Y 8 N Switch case 9 While Loop Until 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 6 7 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 6 7 8 9 10 การทดสอบซอฟต์แวร์

10 Flow Graph Example(2) 1 2 3 4 5 6 7 8 9 10 11 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); 3 4 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. การทดสอบซอฟต์แวร์

12 What is Path? 2 3 4 5 6 7 8 9 10 For example: Path1 = 2-3-4-5-6-8-9-10
12

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

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

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

16 Path Testing Strategies
Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 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
Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 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
Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 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
Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 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 Paths Decisions Process-Link 2 5 a b c d e f g h i j
(a-b-d-f-h-j) T (a-c-e-g-i-j) F (a-b-d-g-i-j) (a-c-e-f-h-j) 1 a 2 b c T F 3 4 d e 5 f T F g 6 7 h i 8 j 9 20 การทดสอบซอฟต์แวร์

21 Exmple Flow Graph 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 then if (a=b) AND (b=c) then Output (“equilateral”) else if (a != b) AND (a != b) AND (b != c) then Output ( “Scalene”) else Output (“Isosceles”) endif endif else Output (“not a triangle”) 22. endif 23. end Triangle2 4 5 6 7 8 9 Flow Graph 10 11 12 13 21 14 15 16 17 18 20 19 22 23

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

23 Test Case for Path Coverage
Path Decision Test case Expected Results 9 13 14 16 a b c T F 100 200 Not A triangle Equilateral 50 60 Scalene 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 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 then if (a=b) AND (b=c) then Output (“equilateral”) else if (a NE b) AND (a NE b) AND (b NE c) then Output ( “Scalene”) else Output (“Isosceles”) endif endif else Output (“not a triangle”) 22. endif 23. end Triangle2 Skip 1- 3 (or w/4) first 5 – A B C D E F H I J K L M N G O last Def of DD-paths on

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

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: = = 5 A B D F T 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 called a strongly connected graph. V(G) = e-n+1 e : the number of edges n : the number of nodes Example: = 5 A B D F T T E F C F G 30 การทดสอบซอฟต์แวร์

31 How to select path Independent Path McCabe’s Baseline
การทดสอบซอฟต์แวร์

32 Independent Path A B D E C F G
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 F T E T F C F G

33 Independent Path Problem of Independent path A B D E C F G 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 F T E T F 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 A B D E C F G 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 F T E T F C F G

36 McCabe’s Path of Triangle Program
First McCabe Paths Expected Results Original P1: First-A-B-C-E-F-H-J-K-M-N-O-Last Scalene Flip P1 at B P2: First-A-B-D-E-F-H-J-K-M-N-O-Last Infeasible path Flip P1 at F P3: First-A-B-C-E-F-G-O-Last Flip P1 at H P4: First-A-B-C-E-F-H-I-N-O-Last Equilateral Flip P1 at J P5: First-A-B-C-E-F-H-J-L-M-N-O-Last Isosceles A B C D E F G H I J K L N M O Last

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. McCabe Paths Expected Results P1 Original P1: First-A-B-C-E-F-H-J-K-M-N-O-Last 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-O-Last Isosceles

38 From path analysis to test case design
b c Expected Results From Path 1 3 4 5 Scalene P1 2 Not a Triangle P6 Equilateral P4 Isosceles P5

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 * rushCharge; } 5. else if (amount >= 200) { 6.      shipcharge = amount * rushCharge; } 7.  else if (amount >= 100) { 8.      shipcharge = rushCharge; } 9.  else if (amount >= 50) { 10.      shipcharge = rushCharge; } 11. else if (amount >= 25) { 12.      shipcharge = rushCharge; }      else { 13.     shipcharge = 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 5 6 7 8 10 9 11 12 13 14

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

43 Basis Path Testing Example
Step 3: Determine the basis set of independent paths. Path 1:  Path 2:  Path 3:  Path 4:  Path 5:  Path 6:  Path 7: 

44 Basis Path Testing Example
step 4: Prepare test cases that force execution of each path in the basis set. Path Nextday Amount Expected Results P1 yes  10 30.48 P2 No 1500 P3 300 345.75 P4 150 P5 75  P6 30 39.425 P7 15.975


Download ppt "Chapter 6 Path Testing Software Testing"

Similar presentations


Ads by Google