Upload
krystal-ketcham
View
234
Download
3
Embed Size (px)
Citation preview
1
Chapter 6 Path Testing
322 235 Software Testing
ByWararat Songpan(Rungworawut),PH.D.
Department of Computer Science, Faculty of Science, Khon Kaen University
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
2
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”
3
4
Flow chart & Flow Graph
1
2
0
3
4
5
6
7 8
9
1011
2
4
7 8 5
9
10 11
Flow Chart Flow Graph
0
1
3
6
Flow Graph Notation
322 235 การทดสอบซอฟต์�แวร� 5
Notation Description
A circle in a graph represents a node, which stands for a sequence of one or more procedural statementsA 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
Flow Graph Example(1)
1. Program ‘Simple Subtraction’2. Input(x,y)3. Output (x)4. Output(y)5. If x> y then Do6. x-y = z7. Else y-x = z8. EndIf9. Output(z)10. Output “End Program”
322 235 การทดสอบซอฟต์�แวร� 6
2
3
4
5
6 7
8
9
10
Flow Graphs consist of• A decision is a program point
at which the control can diverge.
• (e.g., if and case statements)
7
2
3
4
5
6 7
8
9
10
YN
Switch caseWhile Loop
Y
N
Until Loop
Flow Graphs consist of
• A junction is a program point where the control flow can merge.
• (e.g., end if , end loop, goto label)
8
2
3
4
5
6 7
8
9
10
ConnectorGoto
Flow Graphs consist of
• A process block is a sequence of program statements uninterrupted by either decisions of junction.
• (i.e. straight-line code)
322 235 การทดสอบซอฟต์�แวร� 9
2
3
4
5
6 7
8
9
10
Sequence
Flow Graph Example(2)
1. scanf(“%d %d”,&x, &y);2. If (y<0)3. pow = -y; else4. 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);
10
1
23 4
5
6
7
8
910
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 การทดสอบซอฟต์�แวร� 11
What is Path?• For example: Path1 = 2-3-4-5-6-8-9-10
12
2
3
4
5
6 7
8
9
10
What is Path?• For example: Path2 = 2-3-4-5-7-8-9-10
13
2
3
4
5
6 7
8
9
10
Path Testing Strategies• Statement Testing
• 100% statement / node coverage
• Branch Testing o 100% branch/ link coverage
• Path Testing o 100% path coverage
14
1
2
3 4
5
6 7
8
9
a
bc
d e
f g
h i
j
T F
T F
Path Testing Strategies• Statement Testing
• 100% statement / node coverage
• Branch Testing o 100% branch/ link coverage
• Path Testing o 100% path coverage
15
1
2
3 4
5
6 7
8
9
a
bc
d e
f g
h i
j
T F
T F
Path Testing Strategies• Statement Testing
• 100% statement / node coverage
• Branch Testing o 100% branch/ link coverage
• Path Testing o 100% path coverage
16
1
2
3 4
5
6 7
8
9
a
bc
d e
f g
h i
j
T F
T F
Statement Testing < Branch Testing < Path Testing
Path Testing Strategies• Statement Testing
• 100% statement / node coverage
• Branch Testing o 100% branch/ link coverage
• Path Testing o 100% path coverage
17
1
2
3 4
5
6 7
8
9
a
bc
d e
f g
h i
j
T F
T F
Statement Testing < Branch Testing < Path Testing
Path Testing Strategies• Statement Testing
• 100% statement / node coverage
• Branch Testing o 100% branch/ link coverage
• Path Testing o 100% path coverage
18
1
2
3 4
5
6 7
8
9
a
bc
d e
f g
h i
j
T F
T F
Statement Testing < Branch Testing < Path Testing
Path Testing Strategies• Statement Testing
• 100% statement / node coverage
• Branch Testing o 100% branch/ link coverage
• Path Testing o 100% path coverage
19
1
2
3 4
5
6 7
8
9
a
bc
d e
f g
h i
j
T F
T F
Statement Testing < Branch Testing < Path Testing
A Coverage Table
322 235 การทดสอบซอฟต์�แวร� 20
1
2
3 4
5
6 7
8
9
a
b c
d e
PathsDecisions Process-Link
2 5 a b c d e f g h i j
1-2-3-5-6-8-9(a-b-d-f-h-j)
T T
1-2-4-5-7-8-9(a-c-e-g-i-j)
F F
1-2-3-5-7-8-9(a-b-d-g-i-j)
T F
1-2-4-5-6-8-9(a-c-e-f-h-j)
F T
f g
h i
j
T F
T F
20
Exmple Flow Graph
21
4 5 6 7 8
9
10 11
12
13
14
15 16
17 18
1920
21
22
23
1. Program Triangle2. Dim a, b,c As Integer3. 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 = True11. else IsTriangle = False 12. endif
13. If IsTriangle14. 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. endif20. endif21. else Output (“not a triangle”)22. endif23. end Triangle2
Flow Graph
Basis Path Testing
• Select Path is shortest or simple path
• For example: 4-5-6-7-8-9-10-12-13-21-22-23
322 235 การทดสอบซอฟต์�แวร� 2222
4 5 6 7 8
9
10 11
12
13
14
15 16
17 18
1920
21
22
23
Test Case for Path Coverage
Path Decision Test case Expected
Results9 13 14 16 a b c
T F 100 100 200 Not A triangle
F T T 100 100 100 Equilateral
F T F T 100 50 60 Scalene
F T T F 100 100 50 Isosceles23
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
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
24
indegree =1
outdegree =1
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
322 235 การทดสอบซอฟต์�แวร� 2525
Condensation of Code to Table then to Flow
Graph
1. Program Triangle2. Dim a, b,c As Integer3. 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 = True11. else IsTriangle = False 12. endif
13. If IsTriangle14. 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. endif20. endif21. else Output (“not a triangle”)22. endif23. end Triangle2
Def of DD-paths on
code statementPath/nodename
DD-pathCase
Skip 1- 3(or w/4)4 first 15 – 8 A 5
9 B 310 C 411 D 412 E 313 F 314 H 315 I 416 J 317 K 418 L 419 M 320 N 321 G 422 O 323 last 2
DD-Path
27
B
C D
E
F
H
I J
K L
MN
G
O
Last
A
First
4 5 6 7 8
9
10 11
12
13
14
15 16
17 18
1920
21
22
23
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
28
Path Analysis: Cyclomatic
complexity measure (CFC)
CFC can be calculated by
V(G) = e-n+2 e : the number of edgesn : the number of nodes
Example: = 10-7+2 = 5
29
A
B D
E
C F
G
T
FT
F
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 edgesn : the number of nodes
Example: 11-7+1 = 5
322 235 การทดสอบซอฟต์�แวร� 30
A
B D
E
C F
G
T
F
30
T
F
How to select path• Independent Path• McCabe’s Baseline
322 235 การทดสอบซอฟต์�แวร� 31
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-Ao P1: A-B-C-Go P2: A-B-C-B-C-Go P3: A-B-E-F-Go P4: A-D-E-F-Go P5: A-D-F-G
32
A
B D
E
C F
G
T
FT
F
Independent Path
Problem of Independent patho P1: A-B-C-Go P2: A-B-C-B-C-Go P3: A-B-E-F-Go P4: A-D-E-F-Go P5: A-D-F-Go Ex1: A-B-C-B-E-F-Go Ex2: A-B-C-B-C-B-C-G
33
A
B D
E
C F
G
T
FT
F
McCabe’s BaselineTo 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.
34
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
35
A
B D
E
C F
G
T
FT
F
McCabe’s Path of Triangle Program
36
B
C D
E
F
H
I J
K L
MN
G
O
Last
A
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 Infeasible path
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
McCabe’s Path
• Weakness of McCabe’s Path may occur “infeasible path” which means no found test case design to match with the path.
37
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
From path analysis to test case design
Test Case
a b c Expected Results
From Path
1 3 4 5 Scalene P1
2 4 1 2 Not a Triangle P6
3 5 5 5 Equilateral P4
4 3 2 2 Isosceles P5
38
Steps of path testing• Deriving Test Cases1. 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.
39
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 40
Basis Path Testing Example
• Here is a drawing of the flowgraph.
41
12
3
5
7
6
9
8
4
10
11
12
13
14
Basis Path Testing Example
• Step 2: Determine the cyclomatic complexity of the flow graph.
• V(G) = E - N + 2 = 19 - 14 + 2 = 7
42
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
43
Basis Path Testing Example
• step 4: Prepare test cases that force execution of each path in the basis set.
44
Path Nextday Amount Expected Results
P1 yes 10 30.48
P2 No 1500 1713.25
P3 No 300 345.75
P4 No 150 174.125
P5 No 75 90.3875
P6 No 30 39.425
P7 No 10 15.975