Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 9 Instructor Paulo Alencar.

Similar presentations


Presentation on theme: "1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 9 Instructor Paulo Alencar."— Presentation transcript:

1 1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 9 Instructor Paulo Alencar

2 2 Overview  Structural Testing  Introduction – General Concepts  Flow Graph Testing  DD-Paths  Test Coverage Metrics  Basis Path Testing  Guidelines and Observations  Data Flow Testing  Hybrid Methods  Retrospective on Structural Testing

3 3 Structural Testing Also known as glass box, structural, clear box and open box testing. A software testing technique whereby explicit knowledge of the internal workings of the item being tested are used to select the test data. Unlike black box testing that is using the program specification to examine outputs, white box testing is based on specific knowledge of the source code to define the test cases and to examine outputs. http://www.webopedia.com/TERM/W/White_Box_Testing.html

4 4 Structural Testing Structural testing methods are very amenable to: –Rigorous definitions Data flow, control flow, objectives, coverage criteria, relation to programming language semantics –Mathematical analysis Graphs, path analysis –Precise measurement Metrics, coverage analysis

5 5 Program Graph - Definition “Given a program written in an imperative programming language, its Program Graph, is a directed labeled graph in which nodes are either groups of entire statements or fragments of a statement, and edges represent flow of control” P. Jorgensen, “Software Testing a Craftsman’s Approach”

6 6 Program Graph If i, j, are nodes in the program graph, there is an edge from node i, to node j in the program graph if an only if, the statement corresponding to node j, can be executed immediately after the last statement of the group of statement(s) that correspond to node i. The groups of statements that make up a node in the Program Graph is called a basic block. There is a straightforward algorithm to segment a code fragment into basic blocks and create the corresponding Program Graph.

7 7 White-box Testing: Determining the Basic Blocks FindMean (FILE ScoreFile) { float SumOfScores = 0.0; int NumberOfScores = 0; float Mean=0.0; float Score; Read(ScoreFile, Score); while (! EOF(ScoreFile) { if (Score > 0.0 ) { SumOfScores = SumOfScores + Score; NumberOfScores++; } Read(ScoreFile, Score); } /* Compute the mean and print the result */ if (NumberOfScores > 0) { Mean = SumOfScores / NumberOfScores; printf(“ The mean score is %f\n”, Mean); } else printf (“No scores found in file\n”); } 1 2 3 4 5 7 6 8 9

8 8 Constructing the Logic Flow Diagram

9 9 Program Graph - Example

10 10 Flow Graphs – Use in determining Paths for Testing

11 11 Program Graph - Paths Let’s consider the following program graph:

12 12 DD-Paths (1) The best known form of structural testing is based on a construct known as a decision-to-decision path. A DD-Path is a chains obtained from a program graph, where a chain is a path in which the initial and terminal nodes are distinct, and every interior node has indegree = 1, and outdegree = 1. We show in the next slide on selecting the nodes from a program graph to form a DD-Path chain. DD-Paths are used to create DD-Path Graphs. Note that the initial node is 2-connected to every other node in the chain, and there are no instances of 1- or 3- connected nodes. An example of a chain is shown below: Initial node Internal nodes Final node

13 13 DD-Paths (2) More formally a DD-Path is a chain obtained from a program graph such that: –Case1: it consists of a single node with indeg=0. –Case2: it consists of a single node with outdeg=0, –Case3: it consists of a single node with indeg ≥ 2 or outdeg ≥ 2 –Case4: it consists of a single node with indeg =1, and outdeg = 1 –Case5: it is a maximal chain of length ≥ 1

14 14 DD-Path Formation - Example Program Graph NodesDD-Path NameCase # 4first1 5-8A5 9B4 10C4 11D3 12-14E5 15F4 16G3 17H4 18I3 19J4 20K3 21L4 22last2

15 15 DD-Path Graph Given a program written in an imperative language, its DD-Path graph is a labeled directed graph, in which nodes are DD-Paths of its program graph, and edges represent control flow between successor DD-Paths. In this respect, a DD-Path is a condensation graph. For example 2-connected program graph nodes are collapsed to a single DD-Path graph node.

16 16 Program Graph to Table to DD-Path Graph Program Graph NodesDD-Path NameCase # 4first1 5-8A5 9B4 10C4 11D3 12-14E5 15F4 16G3 17H4 18I3 19J4 20K3 21L4 22last2 first A B C D L E F G H I J K last

17 17 Test Coverage Metrics The motivation of using DD-paths is that they enable very precise descriptions of test coverage. In our quest to identify gaps and redundancy in our test cases as these are used to exercise (test) different aspects of a program we use formal models of the program structure to reason about testing effectiveness. Test coverage metrics are a device to measure the extent to which a set of test cases covers a program.

18 18 Example 1 PROGRAM maxsum(maxint, value: INT) 2 INT result:=0; i:=0; 3 IF value < 0 4 THEN value:= - value; 5 WHILE (i<value) AND (result <= maxint) 6 DO i:= i+1; 7Result := result + 1; 8 OD; 9 IF result <= maxint 10 THEN OUTPUT(result) 11 ELSE OUTPUT(“too large”) 12 END

19 19 Test Coverage Metrics MetricDescription of Coverage C0C0 Every Statement C1C1 Every DD-Path C1PC1P Every predicate to each outcome C2C2 C 1 Coverage + loop coverage CdCd C 1 Coverage + every dependent pair of DD-Paths C MCC Multiple condition coverage CikCik Every program path that contains up to k repetitions of a loop (usually k=2) C stat “Statistically significant” fraction of paths C∞C∞ All possible execution paths

20 20 Statement and Predicate Coverage Testing Statement coverage based testing aims to devise test cases that collectively exercise all statements in a program. Predicate coverage (or branch coverage, or decision coverage) based testing aims to devise test cases that evaluate each simple predicate of the program to True and False. Here the term simple predicate refers to either a single predicate or a compound Boolean expression that is considered as a single unit that evaluates to True or False. This amounts to traversing every edge in the DD-Path graph. For example in predicate coverage for the condition if(A or B) then C we could consider the test cases A=True, B= False (true case), and A=False, B=False (false case). Note if the program was encoded as if(A) then C we would not detect any problem.

21 21 DD-Path Graph Edge Coverage C1 12 T F Here a T,T and F,F combination will suffice to have DD-Path Graph edge coverage or Predicate coverage C1 P1 P2

22 22 DD-Path Coverage Testing C 1 P This is the same as the C 1 but now we must consider test cases that exercise all all possible outcomes of the choices T,T, T,F, F,T, F,F for the predicates P1, and P2 respectively, in the DD-Path graph. T F P1 P2

23 23 Multiple Condition Coverage Testing Now if we consider that the predicate P1 is a compound predicate (i.e. (A or B)) then Multiple Condition Coverage Testing requires that each possible combination of inputs be tested for each decision. Example: “if (A or B)” requires 4 test cases: A = True, B = True A = True, B = False A = False, B = True A = False, B = False The problem: For n conditions, 2 n test cases are needed, and this grows exponentially with n.

24 24 Dependent DD-Path Pairs Coverage Testing C d In simple C 1 coverage criterion we are interested simply to traverse all edges in the DD-Path graph. If we enhance this coverage criterion by ensuring that we also traverse dependent pairs of DD-Paths also we may have the chance of revealing more errors that are based on data flow dependencies. More specifically, two DD-Paths are said to be dependent iff there is a define/reference relationship between these DD-Paths, in which a variable is defined (receives a value) in one DD-Path and is referenced in the other. In C d testing we are interested on covering all edges of the DD-Path graph and all dependent DD-Path pairs.

25 25 Loop Coverage The simple view of loop testing coverage is that we must devise test cases that exercise the two possible outcomes of the decision of a loop condition that is one to traverse the loop and the other to exit (or not enter) the loop. An extension would be to consider a modified boundary value analysis approach where the loop index is given a minimum, minimum +, a nominal, a maximum -, and a maximum value or even robustness testing. Once a loop is tested, then the tester can collapse it into a single node to simplify the graph for the next loop tests. In the case of nested loops we start with the inner most loop and we proceed outwards. If loops are knotted then we must apply data flow analysis testing techniques, that we will examine later in the course.

26 26 Statistically Significant Path Coverage Testing Exhaustive testing of software is not practical because variable input values and variable sequencing of inputs result in too many possible combinations to test. NIST developed techniques for applying statistical methods to derive sample test cases would address how to select the best sample of test cases and would provide a statistical level of confidence or probability that a program implements its functional specification correctly. The goal of statistically significant coverage is to develop methods for software testing based on statistical methods, such as Multivariable Testing, Design of Experiments, and Markov Chain usage models, and to develop methods for software testing based on statistical measures and confidence levels. Source: http://www.itl.nist.gov/div897/ctg/stat/mar98ir.pdf

27 27 Basis Path Testing We can apply McCabe’s Cyclomatic Complexity metric –gives an upper bound on number of test cases to ensure edge coverage is satisfied. –in practice, it is usually the “lower bound” of the number of test cases due to the presence of loops.

28 28 Basis Path Testing - Motivation If we consider the paths in a program graph (or DD-Graph) to form a vector space V, we are interested to devise a subset of V say B that captures the essence of V; that is every element of V can be represented as a linear combination of elements of B. Addition of paths means that one path is followed by another and multiplication of a number by a path denotes the repetition of a path. If such a vector space B contains linearly independent paths and forms a “basis” for V then it certainly captures the essence of V.

29 29 McCabe Algorithm to Determine Basis Paths The algorithm is straightforward: –The method begins with the selection of a “baseline path”, which should correspond to a normal execution of a program (from start node to end node, and has as many decisions as possible). –The algorithm proceeds by retracing the paths visited and flipping the conditions one at a time. –The process repeats up to the point all flips have been considered. The objective is to generate test cases that exercise these “basis” paths.

30 30 Flow Graphs – Use in determining Paths for Testing - Revisited

31 31 Example Procedure Validate_Pin(Validate_Pin, Return_Code) Validate_pin = FALSE Return_Code = GOOD Pin_Count = 0 do until Valid_Pin = TRUE or Pin_Count>2 or Return_Code = CANCEL begin get_Pin_Number(Pin_Number, Return_Code) if (Return_Code = CANCEL) begin call Validate_Pin_Number(Pin_Number, Valid_Pin) if (Valid_Pin = FALSE) then begin output “Invalid PIN, please re-enter PIN” Pin_Count = Pin_Count + 1 end return(Valid_Pin, Return_Code)

32 32 Example % macro Euclid 0 data _null_; retain m &m n &n 1if (n>m) then do; 2 r = m; 3 m = n; 4 n = r; 5end; 6r = mod(m, n); 7do while (r ne o); 8 m = n; 9 n = r; 10 r = mod(m, n); 11end; 12put n=; 13run;


Download ppt "1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 9 Instructor Paulo Alencar."

Similar presentations


Ads by Google