Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 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 XXXXX Box testing technique March 2 PP – What type of testing? White or Black?

2 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

3 Path Analysis Why path analysis for test case design?
March 2 PP –Documenting the Triangle Test cases enables another tester to __________, _______, __________. 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 document test cases Path, as previously defined in Graph Theory, is a sequence of connected nodes

4 Overview of Ch. 8.1 Program Graphs
The most common application of graph criteria is in the ___ (not the specification) _______: Usually the control flow graph (CFG) ____ : Execute every statement _____ : Execute every branch _____ : Looping structures such as for loops, while loops, etc. ______ : Augment the CFG defs are statements that assign values to variables uses are statements that use variables March 2 PP Fill in the blanks with: Node coverage Edge coverage Iteration Dataflow coverage Graph Source code

5 Control Flow Graphs (CFG)
A CFG models all executions of a method by describing control structures Nodes : Statements or sequences of statements (basic blocks) Edges : Transfers of control Basic Block : A sequence of statements such that if the first statement is executed, all statements will be (no branches) CFGs are sometimes annotated with extra information branch predicates defs uses Rules for translating statements into graphs …

6 CFG : The if Statement if (x < y) { y = 0; x = x + 1; } else x = y;
4 1 2 3 x >= y x < y x = y y = 0 x = x + 1 3 1 2 x >= y x < y y = 0 x = x + 1 if (x < y) { y = 0; x = x + 1; }

7 CFG : The if-Return Statement
if (x < y) { return; } print (x); 3 1 2 x >= y x < y return print (x) No edge from node 2 to 3. The return nodes must be distinct.

8 Loops Loops require “extra” nodes to be added
Nodes that do not represent statements or basic blocks

9 CFG : while and for Loops
1 x = 0 x = 0; while (x < y) { y = f (x, y); x = x + 1; } 2 dummy node x >= y x < y 1 x = 0 implicitly initializes loop 4 3 y =f(x,y) x = x + 1 2 3 5 x >= y x < y y = f (x, y) 4 for (x = 0; x < y; x++) { y = f (x, y); } x = x + 1 implicitly increments loop

10 CFG : The case (switch) Structure
read ( c) ; switch ( c ) { case ‘N’: y = 25; break; case ‘Y’: y = 50; default: y = 0; } print (y); 5 1 read ( c ); c == ‘N’ y = 0; break; 2 4 3 c == ‘Y’ default y = 50; y = 25; print (y);

11 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. - The statements are represented by the rectangular and diamond blocks (nodes). - The segments between the blocks are the edges, labeled with numbered circles. S1 1 2 C1 March 2 PP State two different Paths using Node: Path1 : S1 – C1 – S3 Path2 : S1 – C1 – S2 – S3 then using edges: Path1: edges (1,4) Path2: edges (1,2,3) 4 S2 3 S3 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.

12 Another Example of Linearly Independent Paths
March 2 PP Give 4 independent paths for this graph S1 1 S2 8 C1 2 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 March 2 PP - What are the edges that make each of the 4 paths linearly independent? 5 C2 3 S3 9 6 C3 4 10 S4 7 S5

13 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 Path1 : S1 – C1 – S3 : edges (1, 4) Path2 : S1 – C1 – S2 – S3 : edges (1, 2. 3 ) 1 2 C1 4 S2 3 S3 PP March 9 - Are both Path1 and Path2 needed to cover all the statements: (S1,C1,S2,S3) ?

14 Another Example of Statement Coverage
1 S2 8 C1 2 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) 5 C2 3 S3 9 6 C3 4 10 S4 7 S5 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 Path !!

15 Statement Coverage Now - - - What do you think of a Software Company
which boasts that they run every statement in the software before release? Try this on some students or other professors and see their reaction.

16 Branch Coverage Method (Also decision-to-decision DD-Paths of our text book)
Identify all the decisions Count all the branches from each of the decisions ( “out-degree” of the decision node) Pick the minimum number of paths that will cover all the branches from the decisions.

17 Branch Coverage Method
One decision C1 : B1 : Path1 : C1 – S3 B2 : Path2 : C1 – S2 S1 1 Branch 1 C1 Branch 2 2 linearly independent paths cover : B1 : Path1 : S1 - C1 – S3 B2 : Path2 : S1 - C1 – S2 – S3 2 4 S2 3 S3 Are both Path1 and Path2 needed to cover Branch1 and Branch2 from C1?

18 Another Example of Branch Coverage
The 3 Decisions and the Branches: C1: PP March 9 - B1 : C1- S2 Give the Paths - B2 : C1- C2 to cover: C2: - B3 : C2 – S3 Are they linearly - B4 : C2 – C3 Independent? C3: - B5 : C3 – S4 - B6 ; C3 – S5 S1 1 S2 8 C1 2 5 C2 3 S3 9 6 C3 4 10 S4 The 4 Linearly Independent Paths Cover: PP March9 Why are each Path needed? Path1: includes S1-C1-S2-S5 Path2: includes S1-C1-C2-S3-S5 Path3: includes S1-C1-C2-C3-S4-S5 Path4: includes S1-C1-C2-C3-S5 7 S5 We need: Path1 to cover B1, Path2 to cover B2 and B3, Path3 to cover B4 and B5, Path4 to cover B6

19 Branch Coverage How do you feel about a Software Company
who states that they test every branch in the Software before release? Does All Branch Coverage subsume All Statements Coverage? include

20 Example Control Flow – Stats
public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i < length; i++) sum += numbers [ i ]; } med = numbers [ length / 2 ]; mean = sum / (double) length; varsum = 0; varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean)); var = varsum / ( length ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ("standard deviation: " + sd); 20 20

21 Control Flow Graph for Stats
public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i < length; i++) sum += numbers [ i ]; } med = numbers [ length / 2 ]; mean = sum / (double) length; varsum = 0; varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean)); var = varsum / ( length ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ("standard deviation: " + sd); 1 2 i = 0 3 i >= length i < length 4 5 i++ 6 i = 0 7 8 i >= length i < length i++ 21 21

22 Control Flow TRs and Test Paths – EC
1 2 TR A. [ 1, 2 ] B. [ 2, 3 ] C. [ 3, 4 ] D. [ 3, 5 ] E. [ 4, 3 ] F. [ 5, 6 ] G. [ 6, 7 ] H. [ 6, 8 ] I. [ 7, 6 ] Test Path [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ] Edge Coverage 3 4 5 6 7 8 22 22

23 Control Flow TRs and Test Paths – EPC
1 TR A. [ 1, 2, 3 ] B. [ 2, 3, 4 ] C. [ 2, 3, 5 ] D. [ 3, 4, 3 ] E. [ 3, 5, 6 ] F. [ 4, 3, 5 ] G. [ 5, 6, 7 ] H. [ 5, 6, 8 ] I. [ 6, 7, 6 ] J. [ 7, 6, 8 ] K. [ 4, 3, 4 ] L. [ 7, 6, 7 ] Test Paths i. [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ] ii. [ 1, 2, 3, 5, 6, 8 ] iii. [ 1, 2, 3, 4, 3, 4, 3, 5, 6, 7, 6, 7, 6, 8 ] Edge-Pair Coverage 2 3 4 TP TRs toured sidetrips 5 i A, B, D, E, F, G, I, J C, H 6 ii A, C, E, H iii A, B, D, E, F, G, I, J, K, L C, H 7 8 23 23

24 Control Flow TRs and Test Paths – PPC
1 TR A. [ 3, 4, 3 ] B. [ 4, 3, 4 ] C. [ 7, 6, 7 ] D. [ 7, 6, 8 ] E. [ 6, 7, 6 ] F. [ 1, 2, 3, 4 ] G. [ 4, 3, 5, 6, 7 ] H. [ 4, 3, 5, 6, 8 ] I. [ 1, 2, 3, 5, 6, 7 ] J. [ 1, 2, 3, 5, 6, 8 ] Test Paths i. [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ] ii. [ 1, 2, 3, 4, 3, 4, 3, 5, 6, 7, 6, 7, 6, 8 ] iii. [ 1, 2, 3, 4, 3, 5, 6, 8 ] iv. [ 1, 2, 3, 5, 6, 7, 6, 8 ] v. [ 1, 2, 3, 5, 6, 8 ] Prime Path Coverage 2 3 4 5 TP TRs toured sidetrips 6 i A, D, E, F, G H, I, J ii A, B, C, D, E, F, G, H, I, J 7 8 iii A, F, H J iv D, E, F, I J v J 24 24

25 Data Flow Coverage for Source
def : a location where a value is stored into memory x appears on the left side of an assignment (x = 44;) x is an actual parameter in a call and the method changes its value x is a formal parameter of a method (implicit def when method starts) x is an input to a program use : a location where variable’s value is accessed x appears on the right side of an assignment x appears in a conditional test x is an actual parameter to a method x is an output of the program x is an output of a method in a return statement If a def and a use appear on the same node, then it is only a DU-pair if the def occurs after the use and the node is in a loop

26 Example Data Flow – Stats
public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i < length; i++) sum += numbers [ i ]; } mean = sum / (double) length; med = numbers [ length / 2 ]; varsum = 0; varsum = varsum + ((numbers [ i ] - mean) * (numbers [ i ] - mean)); var = varsum / ( length ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ("standard deviation: " + sd);

27 Control Flow Graph for Stats
8 1 2 4 3 5 6 7 ( numbers ) sum = 0 length = numbers.length i = 0 i >= length i < length mean = sum / (double) length; med = numbers [ length / 2 ] varsum = 0 i = 0 sum += numbers [ i ] i++ i >= length i < length var = varsum / ( length ) sd = Math.sqrt ( var ) print (length, mean, med, var, sd) varsum = … i++

28 CFG for Stats – With Defs & Uses
8 1 2 4 3 5 6 7 def (1) = { numbers, sum, length } def (2) = { i } use (3, 5) = { i, length } use (3, 4) = { i, length } def (5) = { mean, med, varsum, i } use (5) = { numbers, length, sum } def (4) = { sum, i } use (4) = { sum, numbers, i } use (6, 8) = { i, length } use (6, 7) = { i, length } def (8) = { var, sd } use (8) = { varsum, length, mean, med, var, sd } def (7) = { varsum, i } use (7) = { varsum, numbers, i, mean }

29 Defs and Uses Tables for Stats
Node Def Use 1 { numbers, sum, length } 2 { i } 3 4 { sum, i } { numbers, i, sum } 5 { mean, med, varsum, i } { numbers, length, sum } 6 7 { varsum, i } { varsum, numbers, i, mean } 8 { var, sd } { varsum, length, var, mean, med, var, sd } Edge Use (1, 2) (2, 3) (3, 4) { i, length } (4, 3) (3, 5) (5, 6) (6, 7) (7, 6) (6, 8)

30 DU Pairs for Stats defs come before uses, do not count as DU pairs
variable DU Pairs numbers (1, 4) (1, 5) (1, 7) length (1, 5) (1, 8) (1, (3,4)) (1, (3,5)) (1, (6,7)) (1, (6,8)) med (5, 8) var (8, 8) sd mean (5, 7) (5, 8) sum (1, 4) (1, 5) (4, 4) (4, 5) varsum (5, 7) (5, 8) (7, 7) (7, 8) i (2, 4) (2, (3,4)) (2, (3,5)) (2, 7) (2, (6,7)) (2, (6,8)) (4, 4) (4, (3,4)) (4, (3,5)) (4, 7) (4, (6,7)) (4, (6,8)) (5, 7) (5, (6,7)) (5, (6,8)) (7, 7) (7, (6,7)) (7, (6,8)) defs after use in loop, these are valid DU pairs No def-clear path … different scope for i No path through graph from nodes 5 and 7 to 4 or 3

31 DU Paths for Stats variable DU Pairs DU Paths numbers (1, 4) (1, 5)
(1, 7) [ 1, 2, 3, 4 ] [ 1, 2, 3, 5 ] [ 1, 2, 3, 5, 6, 7 ] length (1, 8) (1, (3,4)) (1, (3,5)) (1, (6,7)) (1, (6,8)) [ 1, 2, 3, 5, 6, 8 ] med (5, 8) [ 5, 6, 8 ] var (8, 8) No path needed sd sum (4, 4) (4, 5) [ 4, 3, 4 ] [ 4, 3, 5 ] variable DU Pairs DU Paths mean (5, 7) (5, 8) [ 5, 6, 7 ] [ 5, 6, 8 ] varsum (7, 7) (7, 8) [ 7, 6, 7 ] [ 7, 6, 8 ] i (2, 4) (2, (3,4)) (2, (3,5)) (4, 4) (4, (3,4)) (4, (3,5)) (5, (6,7)) (5, (6,8)) (7, (6,7)) (7, (6,8)) [ 2, 3, 4 ] [ 2, 3, 5 ] [ 4, 3, 4 ] [ 4, 3, 5 ]

32 DU Paths for Stats – No Duplicates
There are 38 DU paths for Stats, but only 12 unique [ 1, 2, 3, 4 ] [ 1, 2, 3, 5 ] [ 1, 2, 3, 5, 6, 7 ] [ 1, 2, 3, 5, 6, 8 ] [ 2, 3, 4 ] [ 2, 3, 5 ] [ 4, 3, 4 ] [ 4, 3, 5 ] [ 5, 6, 7 ] [ 5, 6, 8 ] [ 7, 6, 7 ] [ 7, 6, 8 ] 2 require at least two iteration of a loop 5 require at least one iteration of a loop 5 expect a loop not to be “entered”

33 Test Cases and Test Paths
Test Case : numbers = (44) ; length = 1 Test Path : [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ] Additional DU Paths covered (no sidetrips) [ 1, 2, 3, 4 ] [ 2, 3, 4 ] [ 4, 3, 5 ] [ 5, 6, 7 ] [ 7, 6, 8 ] The five stars that require at least one iteration of a loop Test Case : numbers = (2, 10, 15) ; length = 3 Test Path : [ 1, 2, 3, 4, 3, 4, 3, 4, 3, 5, 6, 7, 6, 7, 6, 7, 6, 8 ] DU Paths covered (no sidetrips) [ 4, 3, 4 ] [ 7, 6, 7 ] The two stars that require at least two iterations of a loop Other DU paths require arrays with length 0 to skip loops But the method fails with divide by zero on the statement … mean = sum / (double) length; A fault was found

34 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

35 McCabe’s Cyclomatic Complexity Number Earlier Example
We know there are 2 linearly independent paths from before: Path1 : C1 – S3 Path2 : C1 – S2 – S3 S1 1 McCabe’s Cyclomatic Number: a) # of binary decisions +1 = 1 +1 = 2 b) # of edges - # of nodes +2 = = 2 c) # of closed regions + 1 = = 2 C1 2 4 Closed region S2 3 S3

36 McCabe’s Cyclomatic Complexity Number Another Example
McCabe’s Cyclomatic Number: a) # of binary decisions +1 = 2 +1 = 3 b) # of edges - # of nodes +2 = = 3 c) # of closed regions + 1 = = 3 S1 1 4 C1 2 C2 5 S2 There are 3 Linearly Independent Paths Closed Region Closed Region S4 7 6 3 S3

37 An example of 2n total path
Since for each binary decision, there are 2 paths and there 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 S1 1 C1 2 3 S2 4 C2 5 6 S3 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) 7 C3 9 8 S5 S4 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.

38 Example with a Loop Total number of ‘logical’ paths may be “infinite” (very large) because of the loop ---- so we will only look at this “statically” S1 1 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 ) C1 4 S3 2 “One path” will cover all statements: path2 : S1-C1-S2-C1-S3 (S1,C1,S2,S3) S2 3 “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

39 Example with a Loop (cont.)
Total number of ‘logical’ paths may be “infinite” (very large) because of the loop S1 1 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 ) C1 4 S3 2 “One path” will cover all branches: path2 : S1-C1-S2-C1-S3 branch1 (C1-S2) and branch 2 (C1-S3) S2 3 Should we consider the loop boundaries in C1? & also bring in our boundary value testing thoughts?

40 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] e.g. [2,4] = 2[1,0] + 4[0,1] [2,4] [1,0] [0,1]

41 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) 1 path (path4) will cover all statements c) 2 paths will cover all branches. d) 2 branches +1 = 3 linearly independent paths. C1 2 1 S1 1 2 3 4 5 6 3 We pick: path1, path2 and path3 as the Linearly Independent Set path1 1 1 1 C2 5 path2 1 1 4 path3 1 1 1 S2 path4 1 1 1 1 6 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)

42 Other Sets of Linearly Independent Paths
1 2 3 4 5 6 path1 1 1 1 path2 1 1 path3 1 1 1 path4 1 1 1 1 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) 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)

43 More on Linearly Independent Paths
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. C1 2 1 1 2 3 4 5 6 S1 path1 1 1 1 3 path2 1 1 C2 5 path3 1 1 1 4 path4 1 1 1 1 S2 6 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.

44 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 ?

45 An Algorithm to Find the Basis Set
Select a baseline path, an arbitrary, normal execution path that contains as many decisions as possible. Retrace the baseline path and “flip” each of the decision encountered; each flip creates a new path. Continue until all the decisions are flipped The basis set is composed of all the paths generated from steps 1 and 2 above Cyclomatic # = 2+ 1 = 3; So there are 3 linearly independent paths C1 2 1 S1 1. pick baseline path P1: C1 –S1- C2 – S2: <0,1,1,0,1,1> 2. flip C P2 : C1 – C2 – S : <1,0,0,0.1,1> 3. flip C P3: C1 - C : <1,0,0,1,0,0> 3 C2 5 4 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 S2 6

46 Total “Possible” Logical Paths can be Big!
There are 5 choices each time we process through this 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 = 125 possible paths! c1 1 c2 c3 2 4 s2 5 3 s3 You also note that for n loops there may be 3n decisions. e.g.: We have 3*3 = 9 decisions for looping 3 times. c4 s4

47 Paths Analysis Interested in total number of all possible combinations of “logical” paths Interested in Linearly Independent paths Interest in Branch coverage or decision-to- decision (DD)-path Interested in Statement coverage Which one do you think is the largest set, next largest, , etc.? Compare this list with page 137(Ed4 136 Ed3) of your text what are we missing?

48 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: It consists of a single node with in-degree = 0 (initial node) It consists of a single node with out-degree = 0 (terminal node) It consists of a single node with in-deg => 2 or out-deg => 2 It consists of a single node with in-deg = 1 and out-deg = 1 It is a maximal chain of length => 1.

49 Condensation of Code to Table then to Graph
Psuedo-code Path/node name DD-path Def. 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 Page 140

50 Condensation Graph from Table
- Statements coverage paths - Branch (DD-path) coverage paths - Cyclomatic # = 4+1 = lin. Ind paths - All combinations paths first A B C D E F H G J I K L M N O Last

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

52 Summary Applying the graph test criteria to control flow graphs is relatively straightforward Most of the developmental research work was done with CFGs A few subtle decisions must be made to translate control structures into the graph Some tools will assign each statement to a unique node These slides and the book uses basic blocks Coverage is the same, although the bookkeeping will differ


Download ppt "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."

Similar presentations


Ads by Google