path testing path testing is a “design structural testing” in that it is based on detailed...

30
Path testing Path testing is a “design structural testing ” in that it is based on detailed design & the source code of the program to be tested. The methodology uses the graphical representation of the source code Thus it is very much “control flow ” or “path ” oriented This methodology has been available since the mid-1970’s and is an important White Box testing technique

Upload: morgan-marshall

Post on 23-Dec-2015

220 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Path testing

• Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested.

• The methodology uses the graphical representation of the source code– Thus it is very much “control flow” or “path”

oriented

• This methodology has been available since the mid-1970’s and is an important White Box testing technique

Page 2: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Transforming Code to Diagram

• In early chapter (chapter 4) on graph theory, we mentioned condensation graph as a graph that was derived by “condensing” a component (or set of code) into a node as a way to simplify the graphical diagram of source code.

• Here we will :– assume that we have a condensed graph and

discuss path analysis

Page 3: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Path Analysis

• Why path analysis for test case design?– Provides a systematic methodology of White Box

testing.• Reproducible• Traceable• Countable

• 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

Reasons similar to why documenttest cases

Path, as previously defined in Graph Theory, is a sequence of connected nodes

Page 4: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Linearly Independent Path

• A path through the system is Linearly Independent** from other paths only if it includes some segment or edge that is not covered in the other paths.

S1

S3

S2

C1

1

4

2

3

- The statements are representedby the rectangular and diamond blocks (nodes).- The segments between the blocks arethe edges, labeled with numbered circles.

Path1 : S1 – C1 – S3Path2 : S1 – C1 – S2 – S3 ORPath1: edges (1,4)Path2: edges (1,2,3)

Path1 and Path2 are linearly independent because each includes some edge that is not included in the others. (note: not necessarily nodes)

** This definition will require more explanation later.

Page 5: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Another Example of Linearly Independent Paths

S1

S2

S3

S4

S5

C1

C2

C3

1

5

6

7

2

4

3

10

9

8

Path1: edges (1,2,8)Path2: edges (1,5,3,9)Path3: edges (1,5,6,4,10)Path4: edges (1,5,6,7)

Note that these are all linearly independent

Page 6: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Statement Coverage Method• Count all the linearly independent paths• Pick the minimum number of linearly independent paths that will

include all the statements (nodes) (S’s and C’s in the diagram)

S1

S3

S2

C1

1

4

2

3

Path1 : S1 – C1 – S3 : edges (1, 4)Path2 : S1 – C1 – S2 – S3 : edges (1, 2. 3 )

Are both Path1 and Path2 needed to cover all the statements: (S1,C1,S2,S3) ? What would you say?

Page 7: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Another Example of Statement Coverage

S1

S2

S3

S4

S5

C1

C2

C3

1

5

6

7

2

4

3

10

9

8

The 4 Linearly Independent Paths Covers:

Path1: includes S1-C1-S2-S5 : edges (1,2,8)Path2: includes S1-C1-C2-S3-S5 : edges ( 1,5,3,9)Path3: includes S1-C1-C2-C3-S4-S5 : edges (1,5,6,4,10)Path4: includes S1-C1-C2-C3-S5 : edges (1,5,6,7)

For 100% Statement Coverage, all we need are 3 paths : Path1, Path2, and Path3 to cover all the statements (S1,C1,S2,C2,S3,C3,S4,S5) - - - no need for Path4 - - - - !!

Page 8: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Statement Coverage

Now - - -

What do you think of a Software Companywhich boasts that they run every statementin the software before release?

Try this on some students or other professorsand see their reaction.

Page 9: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Branch Coverage Method(Also DD-Paths of our text book)

1. Identify all the decisions

2. Count all the branches from each of the decisions ( “out-degree” of the decision node)

3. Pick the minimum number of paths that will cover all the branches from the decisions.

Page 10: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Branch Coverage Method

S1

S3

S2

C1

1

4

2

3

One decision C1 :

B1 : Path1 : C1 – S3 B2 : Path2 : C1 – S2

Are both Path1 and Path2 needed to cover Branch1 and Branch2 from C1?

Branch 1 Branch 2

2 linearly independent paths cover :

B1 : Path1 : S1 - C1 – S3 B2 : Path2 : S1 - C1 – S2 – S3

Page 11: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Another Example of Branch Coverage

S1

S2

S3

S4

S5

C1

C2

C3

1

5

6

7

2

4

3

10

9

8

The 3 Decisions and the Branches:

C1: - B1 : C1- S2 - B2 : C1- C2 C2: - B3 : C2 – S3 - B4 : C2 – C3 C3: - B5 : C3 – S4 - B6 ; C3 – S5

We need: Path1 to cover B1, Path2 to cover B2 and B3, Path3 to cover B4 and B5, Path4 to cover B6

The 4 Linearly Independent Paths Cover:

Path1: includes S1-C1-S2-S5Path2: includes S1-C1-C2-S3-S5Path3: includes S1-C1-C2-C3-S4-S5Path4: includes S1-C1-C2-C3-S5

Page 12: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Branch Coverage

How do you feel about a Software Companywho states that they test every branch in theSoftware before release?

Does All Branch Coverage subsume All Statements Coverage?

Page 13: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

McCabe’s Cyclomatic Number

• Is there a way to know how many linearly independent paths exist?– McCabe’s Cyclomatic number which we used to

study program complexity may be applied. There are 3 ways to get the Cyclomatic Complexity number from a flow diagram.

• # of binary decisions + 1 • # of edges - # of nodes + 2• # of closed regions + 1

Page 14: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

McCabe’s Cyclomatic Complexity NumberEarlier Example

S1

S3

S2

C1

1

4

2

3

We know there are 2 linearly independentpaths from before: Path1 : C1 – S3 Path2 : C1 – S2 – S3

McCabe’s Cyclomatic Number:

a) # of binary decisions +1 = 1 +1 = 2

b) # of edges - # of nodes +2 = 4-4+2 = 2

c) # of closed regions + 1 = 1 + 1 = 2

Closed region

Page 15: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

McCabe’s Cyclomatic Complexity NumberAnother Example

S1

S3

S2

C1

1

4

2

3

McCabe’s Cyclomatic Number:

a) # of binary decisions +1 = 2 +1 = 3

b) # of edges - # of nodes +2 = 7-6+2 = 3

c) # of closed regions + 1 = 2 + 1 = 3

Closed Region

C2

S47

5

6

Closed Region

There are 3 Linearly Independent Paths

Page 16: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

An example of 2n total path

S1

C1

C2

C3

S2

S3

S4S5

2

1

3

4

5

6

8

9

7

Since for each binary decision, there are 2 paths andthere are 3 in sequence, there are 23 = 8 total “logical” paths path1 : S1-C1-S2-C2-C3-S4 path2 : S1-C1-S2-C2-C3-S5 path3 : S1-C1-S2-C2-S3-C3-S4 path4 : S1-C1-S2-C2-S3-C3-S5

path5 : S1-C1-C2-C3-S4 path6 : S1-C1-C2-C3-S5 path7 : S1-C1-C2-S3-C3-S4 path8 : S1-C1-C2-S3-C3-S5

How many Linearly Independent paths are there?Using Cyclomatic number = 3 decisions +1 = 4

One set would be: path1 : includes edges (1,2,4,6,9) path2 : includes edges (1,2,4,6,8) path3 : includes edges (1,2,4,5,7,9) path5 : includes edges (1,3,6,9)

Note 1: with just 2 paths ( Path1 and Path8) all the statements are covered.

Note2: with just 2 paths ( Path1 and Path8) all the branches are covered.

Page 17: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Example with a Loop

S1

S2

S3C1

3

2

1

4

Total number of ‘logical’ paths may be “infinite” (very large) because of the loop ---- so we will only look at this “statically”

Linearly Independent Paths = 1 decision +1 = 2

path1 : S1-C1-S3 (segments 1,4 ) path2 : S1-C1-S2-C1-S3 (segments 1,2,3,4 )

“One path” will cover all statements: path2 : S1-C1-S2-C1-S3 (S1,C1,S2,S3)

“One path” will cover all branches: path2 : S1-C1-S2-C1-S3 branch1 (C1-S2) and branch 2 (C1-S3)

*** Note***: To get one path --- S2 must somehow change C1

Page 18: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Example with a Loop (cont.)

S1

S2

S3C1

3

2

1

4

Total number of ‘logical’ paths may be “infinite” (very large) because of the loop

Linearly Independent Paths = 1 decision +1 = 2

path1 : S1-C1-S3 (segments 1,4 ) path2 : S1-C1-S2-C1-S3 (segments 1,2,3,4 )

“One path” will cover all branches: path2 : S1-C1-S2-C1-S3 branch1 (C1-S2) and branch 2 (C1-S3)

Should we considerthe loop boundaries in C1? & also bring in our boundary value testing thoughts?

Page 19: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

More on Linearly Independent Paths

• In discussing dimensionality, we talks about orthogonal vectors (or “basis” of vector space) .

– (e.g.) Two dimensional space has two orthogonal vector from which all the other vectors in two dimension can be obtained via “linear combination” of these 2 vectors:

• [1,0]• [0,1]

[1,0]

[0,1]

[2,4]

e.g. [2,4] = 2[1,0] + 4[0,1]

Page 20: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

More on Linearly Independent Paths

• A set of paths is considered to be a Linearly Independent Set if every path may be constructed as a “linear combination” of paths from the linearly independent set. For example:

C1

C2

S1

S2

6

5

4

3

21

We already know: a) there are a total of 22=4 logical paths. b) 1 path (path4) will cover all statements c) 2 paths will cover all branches. d) 2 branches +1 = 3 linearly independent paths.

path1

path2

path3

path4

1 2 3 4 5 6

1 1 1

1 1

1 1 1

1 1 1 1

path 4 = path3 + path1 – path2 = (0,1,1,1,0,0)+(1,0,0,0,1,1)- (1,0,0,1,0,0) = (1,1,1,1,1,1) - (1,0,0,1,0,0) = (0,1,1,0,1,1)

We pick: path1,path2 and path3 as the Linearly Independent Set

Page 21: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Other Sets of Linearly Independent Paths

-Consider the set of linearly independent paths: 1, 2 & 4 instead.

- Can we get Path3 = (0,1,1,1,0,0)?-Consider path3 = path2 + path4 – path1 = (1,0,0,1,0,0,)+(0,1,1,0,1,1) – (1,0,0,0,1,1) = (0,1,1,1,0,0)

path1

path2

path3

path4

1 2 3 4 5 6

1 1 1

1 1

1 1 1

1 1 1 1

-Consider another set of linearly independent paths: 2, 3 & 4 instead.

- Can we get Path 1 = (1,0,0,0,1,1))?-Consider path1 = path2 + path4 – path3 = (1,0,0,1,0,0,)+(0,1,1,0,1,1) – (0,1,1,1,0,0) = (1,0,0,0,1,1)

Page 22: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

More on Linearly Independent Paths

C1

C2

S1

S2

6

5

4

3

21

path1

path2

path3

path4

1 2 3 4 5 6

1 1 1

1 1

1 1 1

1 1 1 1

Note : Although path1 and path3 are linearly independent, they do NOT form a Linearly Independent Set because no linear combination of path1 and path3 can get , say, path4.

We already know: a) there are a total of 22=4 logical paths. b) 1 path (path4) will cover all statements c) 2 paths will cover all branches. d) 2 branches +1 = 3 linearly independent paths.

Page 23: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

More on Linearly Independent Paths

• Because the Linearly Independent Set of paths display the same characteristics as the mathematical concept of basis in n-dimensional vector space, the testing using the Linearly Independent Set of paths is sometimes called the “basis” testing.

• The main notion is that since the “linear independent set of paths” as a set can span all the paths for the design/code construct, then basis testing covers the “essence” of the whole structure.

Then ------ is there a way to find a Linearly Independent Set ?

Page 24: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

An Algorithm to Find the Basis Set1. Select a baseline path, an arbitrary, normal execution path

that contains as many decisions as possible.2. Retrace the baseline path and “flip” each of the decision

encountered; each flip creates a new path. Continue until all the decisions are flipped

3. The basis set is composed of all the paths generated from steps 1 and 2 above

C1

C2

S1

S2

6

4

3

21

1. pick baseline path P1: C1 –S1- C2 – S2: <0,1,1,0,1,1> 2. flip C1 P2 : C1 – C2 – S2 : <1,0,0,0.1,1>3. flip C2 P3: C1 - C2 : <1,0,0,1,0,0>

Cyclomatic # = 2+ 1 = 3;So there are 3 linearly independent paths

5

Can we get the 4th path : C1 – S1 – C2 : <0,1,1,1,0,0> from the above basis set?

How about : (P1 + P3) – P2 ?(P1 + P3) – P2 = (<0,1,1,0,1,1> + <1,0,0,1,0,0>) - <1,0,0,0,1,1> = <1,1,1,1,1,1> - <1,0,0,0,1,1> = <0,1,1,1,0,0> = P4

Page 25: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Total “Possible” Logical Paths can be Big!

s1

c1

s2 c3

s3

c2

c4

s4

4

1

2

35

There are 5 choices each time we process throughthis loop.

For passing through the loop n times we have 5n

possibilities of logical paths.

If we go through the loop just 3 times, we have (5)3 = 125possible paths!

You also note that for nloops there may be 3n decisions. e.g.:We have 3*3 = 9 decisions for looping 3 times.

Page 26: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Paths Analysis

• Interested in total number of all possible combinations of “logical” paths

• Interested in Linearly Independent paths• Interest in Branch coverage or DD-path• Interested in Statement coverage

Which one do you think is the largest set, next largest, - - - , etc.?

Compare this list with page 136 of your text - - - what are we missing?

Page 27: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Definition for DD-path

• DD (decision-decision) path is a path of nodes in a directed graph.

• A chain is a path in which:– Initial and terminal nodes are distinct (not just one node)– All interior nodes have in-degree = 1 and out-degree =1

• A DD-path is a chain in a program graph such that the following are included in the chain:

1. It consists of a single node with in-degree = 0 (initial node)

2. It consists of a single node with out-degree = 0 (terminal node)

3. It consists of a single node with in-deg => 2 or out-deg => 2

4. It consists of a single node with in-deg = 1 and out-deg = 1

5. It is a maximal chain of length => 1.

Page 28: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Condensation of Code to Table then to 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

Psuedo-code

Def of DD-paths on

Page 140

code statementPath/nodename

DD-pathDef.

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

Page 29: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Condensation Graph from Table

first

A

B

C D

E

F

G H

I J

K L

MN

O

Last

- Statements coverage - 4 paths- Branch (DD-path) coverage - 4 paths- Cyclomatic # = 4+1 = 5 - 5 lin. Ind paths- All combinations - 8 paths

Page 30: Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology

Closer Look into Path Testing

• Look at 2 paths from A to E. The paths of either it is a triangle or not a triangle.

– But there are many combinations to get “not triangle” ; so we still need to consider utilizing boundary values and equivalence class. Just one test case to cover the path may not be enough

• Look at the path that leads from D to L (D= not triangle and L= Isosceles triangle). Is that path possible - - - can you generate a test case for that path?

• Look at the path from C to G (C = Is a triangle and G = output “not triangle”) - - - is this a possible path?

– There may be logical dependencies that prevent us from generating test case to traverse certain paths. Thus we also need to consider employing decision tables from Black Box testing technique.