Presentation on theme: "Path Analysis Why path analysis for test case design?"— Presentation transcript:
1 Path Analysis Why path analysis for test case design? Provides a systematic methodology.ReproducibleTraceableCountableWhat is path analysis?Analyzes the number of paths that exist in the systemFacilitates the decision process of how many paths to include in the test
2 Linearly Independent Path A path through the system is Linearly Independent** from other paths only if it includes some segment that is not covered in the other path.S1- The statements are representedby the rectangular and diamond blocks.- The segments between the blocks arelabeled with numbered circles.12C1Path1 : S1 – C1 – S3Path2 : S1 – C1 – S2 – S3ORPath1: segments (1,4)Path2: segments (1,2,3)4S23S3Path1 and Path2 are linearly independent because each includes somesegment that is not included in the other.** This definition will require more explanation later.
3 Another Example of Linearly Independent Paths 1S28C12Path1: segments (1,2,8)Path2: segments (1,5,3,9)Path3: segments (1,5,6,4,10)Path4: segments (1,5,6,7)Note that these are all linearly independent5C23S396C3410S47S5
4 Statement Coverage Method Count all the linearly independent pathsPick the minimum number of linearly independent paths that will include all the statements (S’s and C’s in the diagram)S1Path1 : S1 – C1 – S3Path2 : S1 – C1 – S2 – S312C14S23S3Path1 and Path2 are needed to cover all the statements: (S1,C1,S2,S3) ?
5 Another Example of Statement Coverage 1S28C12The 4 Linearly Independent Paths Covers:Path1: includes S1-C1-S2-S5Path2: includes S1-C1-C2-S3-S5Path3: includes S1-C1-C2-C3-S4-S5Path4: includes S1-C1-C2-C3-S55C23S396C3410S47S5For 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 Path
6 Branch Coverage Method Identify all the decisionsCount all the branches from the each of the decisionsPick the minimum number of paths that will cover all the branches from the decisions.
7 Branch Coverage Method S1Decision C1 :B1 : Path1 : C1 – S3B2 : Path2 : C1 – S2 – S31Branch 1C1Branch 224S23S3Path1 and Path2 are needed to cover both branches from C1?
8 Another Example of Branch Coverage The 3 Decisions:C1:- B1 : C1- S2- B2 : C1- C2C2:- B3 : C2 – S3- B4 : C2 – C3C3:- B5 : C3 – S4- B6 ; C3 – S5S11S28C125C23S396C3410S4The 4 Linearly Independent Paths Covers:Path1: includes S1-C1-S2-S5Path2: includes S1-C1-C2-S3-S5Path3: includes S1-C1-C2-C3-S4-S5Path4: includes S1-C1-C2-C3-S57S5We need:Path1 to cover B1,Path2 to cover B2 and B3,Path3 to cover B4 and B5,Path4 to cover B6
9 McCabe’s Cyclomatic Number Is there a way to know how many linearly independent paths exist?McCabe’s Cyclomatic number 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 + 1Reference: T.J. McCabe, “A complexity Measure,” IEEE Transactions on Software Engineering, Dec. 1976
10 McCabe’s Cyclomatic Complexity Number Earlier Example We know there are 2 linearly independentpaths from before:Path1 : C1 – S3Path2 : C1 – S2 – S3S11McCabe’s Cyclomatic Number:a) # of binary decisions +1 = 1 +1 = 2b) # of edges - # of nodes +2 = = 2c) # of closed regions + 1 = = 2C124Closed regionS23S3
11 McCabe’s Cyclomatic Complexity Number Another Example McCabe’s Cyclomatic Number:a) # of binary decisions +1 = 2 +1 = 3b) # of edges - # of nodes +2 = = 3c) # of closed regions + 1 = = 3S114C12C25S2There are 3 LinearlyIndependent PathsClosed RegionClosed RegionS4763S3
12 An example of 2n total path Since for each binary decision, there are 2 paths andthere are 3 in sequence, there are 23 = 8 total “logical” pathspath1 : S1-C1-S2-C2-C3-S4path2 : S1-C1-S2-C2-C3-S5path3 : S1-C1-S2-C2-S3-C3-S4path4 : S1-C1-S2-C2-S3-C3-S5path5 : S1-C1-C2-C3-S4path6 : S1-C1-C2-C3-S5path7 : S1-C1-C2-S3-C3-S4path8 : S1-C1-C2-S3-C3-S5S11C123S24C256S3How many Linearly Independent paths are there?Using Cyclomatic number = 3 decisions +1 = 4One set would be:path1 : includes segments (1,2,4,6,9)path2 : includes segments (1,2,4,6,8)path3 : includes segments (1,2,4,5,7,9)path5 : includes segments (1,3,6,9)7C398S5S4Note 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.
13 Example with a LoopTotal number of paths may be “ infinite” (very large)because of the loopS11Linearly Independent Paths = 1 decision +1 = 2path1 : S1-C1-S3 (segments 1,4)path2 : S1-C1-S2-C1-S3 (segments 1,2,3,4)C14S32One path will cover all statements: (S1,C1,S2, S3)path2 : S1-C1-S2-C1-S3S23One path will cover all branches:path2 : S1-C1-S2-C1-S3branch1 (C1-S2) andbranch 2 (C1-S3)
14 More on Linearly Independent Paths In discussing dimensionality, we talks about orthogonal vectors.Two dimensional space has two orthogonal vector from which all the other vectors in two dimension can be obtained via “linear combination” of these vectors:[1,0][0,1]e.g.[2,4] = 2[1,0] + 4[0,1][2,4][1,0][0,1]
15 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:We already know: a) there are a total of 22=4 logical paths.b) 2 paths that will cover all statementsand all branches.c) 2 branches +1 = 3 linearly independent paths.C121S11234563We picked path1,path2 and path3 asThe LinearlyIndependent Setpath1111C25path2114path3111S1path411116path 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)
16 More on Linearly Independent Paths We already know: a) there are a total of 22=4 logical paths.b) 2 paths that will cover all statementsand all branches.c) 2 branches +1 = 3 linearly independent paths.C121S11234563path1111C25path2114path3111S1path411116Although 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.
17 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.
18 Paths Analysis Interested in Total number of “logical” paths Interested in Linearly Independent pathsInterest in Branch coverageInterested in Statement coverageWhich one is the largest set, next largest set, , etc.?