Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

COM3082C2 - Systems Development slide 6- 1


Published on

COM3082C2 - Systems Development slide 6- 1

  1. 1. Software Testing Dr Z He University of Ulster
  2. 2. Lecture 6: Software Testing <ul><li>Objectives </li></ul><ul><ul><li>Issues of software testing </li></ul></ul><ul><ul><ul><li>Software testing, Software testing principles, Need for testing </li></ul></ul></ul><ul><ul><li>Verification and validation </li></ul></ul><ul><ul><li>Testing stages </li></ul></ul><ul><ul><ul><li>unit, integration, system, acceptance </li></ul></ul></ul><ul><ul><li>Test Planning </li></ul></ul><ul><ul><ul><li>Test plan </li></ul></ul></ul><ul><ul><li>Techniques for testing </li></ul></ul><ul><ul><ul><li>static: reading, walkthrough and inspections, correctness proofs, stepwise abstraction </li></ul></ul></ul><ul><ul><ul><li>dynamic: functional, structural </li></ul></ul></ul><ul><ul><li>Testing Coverage </li></ul></ul><ul><ul><li>Further Testing Stages </li></ul></ul>
  3. 3. Software Testing <ul><ul><li>once source code has been generated, software must be tested to uncover(and correct) as many errors as possible before delivery to the customer </li></ul></ul><ul><ul><li>the goal is to design a series of test cases that have a high likelyhood of finding errors </li></ul></ul><ul><ul><li>software testing techniques provide systematic guidance for designing tests that </li></ul></ul><ul><ul><ul><li>exercise the internal logic of software components, and </li></ul></ul></ul><ul><ul><ul><li>exercise the input and output domains of the program to uncover errors in program function, behaviour and performance </li></ul></ul></ul><ul><ul><li>is a process of executing a program with intent of finding an error </li></ul></ul><ul><ul><li>a good test case is one that has a high probability of finding an uncovered error </li></ul></ul><ul><ul><li>a successful test is one that uncovers an undiscovered error </li></ul></ul><ul><ul><li>cannot show the absence of errors and defects, it can only show that software error and defect are present </li></ul></ul>
  4. 4. Software Testing Principles <ul><li>All tests should be traceable to customer requirements </li></ul><ul><li>Tests should be planned before testing begins. Test planning can begin as soon as the requirements model is complete. Detailed definition of test cases can begin as soon as the design model has been solidified </li></ul><ul><li>Pareto principle applies to software testing (80% of all errors uncovered during testing will likely to be traceable to 20% of all program components) </li></ul><ul><li>Testing should begin in small (components) and progress toward testing in large(ultimately the entire system) </li></ul><ul><li>Exhaustive testing is not possible </li></ul><ul><li>To be most effective, testing should be conducted by an independent third party </li></ul>
  5. 5. Need for Testing <ul><li>30-85 errors per 1000 lines of code (Boehm 1981) </li></ul><ul><li>After testing, 0.5-3 errors per 1000 lines of code (Myers 1986) </li></ul><ul><li>Errors are expensive </li></ul><ul><li>The later errors are found the more expensive they are to fix </li></ul>Cost to fix Requirements Operation <ul><ul><li>Phase </li></ul></ul>
  6. 6. Need for Testing <ul><li>Testing shows presence of errors but cannot prove their absence </li></ul><ul><li>In most cases it is impossible to test exhaustively </li></ul><ul><li>E.g. </li></ul><ul><ul><li>for i from 1 to 100 do </li></ul></ul><ul><ul><li>print (if a[i] = true then 1 else 0 endif); </li></ul></ul><ul><ul><li>has 2 100 different outcomes - approx. 3x10 14 years to exhaustively test. Given a machine can execute 10 million print instructions per second. </li></ul></ul>
  7. 7. Verification and Validation <ul><li>Verification - ‘Are we building the product right’? </li></ul><ul><li>Validation - ‘Are we building the right product’? </li></ul><ul><li>1. At the requirements analysis stage </li></ul><ul><li>cheapest to correct at this stage </li></ul><ul><li>Test criteria: </li></ul><ul><ul><li>completeness - are all the requirements gathered </li></ul></ul><ul><ul><li>consistency - no contradictions within the system or with external components </li></ul></ul><ul><ul><li>feasibility - benefits should outweigh costs </li></ul></ul><ul><ul><li>testability - requirements should be unambiguous, otherwise they cannot be tested </li></ul></ul>
  8. 8. Verification and Validation <ul><li>2. At the Design stage </li></ul><ul><li>criteria as for requirements stage. </li></ul><ul><li>Elements from the requirements should be traced to the design </li></ul><ul><li>simulation, walkthroughs, inspections to test quality </li></ul>
  9. 9. Verification and Validation <ul><li>3. Implementation stage </li></ul><ul><li>Programs can be checked by reading through them (not by the author) </li></ul><ul><li>Stepwise abstraction - determine the function of code from a number of its steps </li></ul><ul><li>Tools are available to support the testing of code </li></ul><ul><ul><li>Static analysis - test the code without running it - E.g. have all the variables been declared? </li></ul></ul><ul><ul><li>Dynamic analysis - test by executing the code </li></ul></ul>
  10. 10. <ul><li>Unit testing </li></ul><ul><ul><li>testing of individual components </li></ul></ul><ul><li>Integration testing </li></ul><ul><ul><li>testing collections of modules integrated into sub-systems </li></ul></ul><ul><li>System testing </li></ul><ul><ul><li>testing the complete system prior to delivery </li></ul></ul><ul><li>Acceptance testing </li></ul><ul><ul><li>testing by users to check that the system satisfies requirements. Sometimes called alpha(  ) testing </li></ul></ul>Testing Stages
  11. 11. Testing Stages S u b - s y s t e m t e s t i n g U n i t t e s t i n g S y s t e m t e s t i n g A c c e p t a n c e t e s t i n g
  12. 12. <ul><li>Test Plan </li></ul><ul><ul><li>The testing process </li></ul></ul><ul><ul><li>Requirements traceability </li></ul></ul><ul><ul><li>Tested items </li></ul></ul><ul><ul><li>Testing schedule </li></ul></ul><ul><ul><li>Test recording procedures </li></ul></ul><ul><ul><li>Hardware and software requirements </li></ul></ul><ul><ul><li>Constraints </li></ul></ul>Test Planning
  13. 13. Techniques for Testing - Static <ul><li>1. Reading, Walkthroughs and inspection s </li></ul><ul><li>All involve someone else looking at the code </li></ul><ul><li>Look for </li></ul><ul><ul><li>inappropriate usage of data. E.g. uninitialised variables, arrays out of bounds, dangling pointers </li></ul></ul><ul><ul><li>errors in declarations. E.g. undeclared variables, repeated names </li></ul></ul><ul><ul><li>Faults in computations. E.g. division by zero, overflow, type mismatches, erroneous operator order (*,/,+,- etc.) </li></ul></ul><ul><ul><li>faults in logical operators. E.g. < instead of > </li></ul></ul><ul><ul><li>faults in control. E.g. infinite loops, loop executing the wrong number of times </li></ul></ul><ul><ul><li>faults in interfaces. E.g. Wrong number of parameters </li></ul></ul><ul><li>Many of these are detected by the compiler </li></ul><ul><li>Can be applied to documents </li></ul><ul><li>Can be applied to all stages of life cycle </li></ul>
  14. 14. Techniques for Testing - Static <ul><li>2. Correctness Proofs </li></ul><ul><li>Does a program meet its specification. </li></ul><ul><li>If specification is expressed formally and proved the program can be proved </li></ul><ul><li>Difficult to use. </li></ul><ul><li>Cannot prove every aspect. </li></ul><ul><li>Validation can only be done by testing. </li></ul><ul><li>3. Stepwise Abstraction </li></ul><ul><li>bottom-up process </li></ul><ul><li>start with code and derive functions </li></ul><ul><li>check these with the requirements </li></ul>
  15. 15. Techniques for Testing - Dynamic <ul><li>Dynamic Testing Techniques </li></ul><ul><ul><li>Black Box Testing </li></ul></ul><ul><ul><ul><li>also called functional testing , or behavioural testing </li></ul></ul></ul><ul><ul><ul><li>focuses on the functional requirements of the software </li></ul></ul></ul><ul><ul><ul><li>enables the software engineer to derive sets of input conditions that will fully exercise all functional requirements for a program (test cases derived from specifications) </li></ul></ul></ul><ul><ul><ul><li>tends to be applied during later stages of testing </li></ul></ul></ul><ul><ul><ul><li>purposely disregards control structure, attention is focused on the information domain </li></ul></ul></ul><ul><ul><ul><li>exhaustive functional testing is normally not feasible </li></ul></ul></ul><ul><ul><ul><li>use characteristics of input domain to find the minimum set of test cases to reveal most defects </li></ul></ul></ul><ul><ul><ul><li>we will study: </li></ul></ul></ul><ul><ul><ul><ul><li>Equivalence Partitioning </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Boundary value analysis </li></ul></ul></ul></ul>
  16. 16. Techniques for Testing - Dynamic <ul><li>Dynamic Testing Techniques </li></ul><ul><ul><li>White Box Testing </li></ul></ul><ul><ul><ul><li>also called glass box testing , or structural testing </li></ul></ul></ul><ul><ul><ul><li>uses the control structure of the procedural design to derive test cases </li></ul></ul></ul><ul><ul><ul><li>exhaustive structural testing is normally not feasible </li></ul></ul></ul><ul><ul><ul><li>to find the minimum set of test cases to exercise most important logical paths </li></ul></ul></ul><ul><ul><ul><li>We will study: </li></ul></ul></ul><ul><ul><ul><ul><li>Basis Path Testing </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Loop Testing </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Testing Coverage </li></ul></ul></ul></ul>
  17. 17. Techniques for Testing - Dynamic <ul><li>Equivalence Partitioning </li></ul><ul><ul><li>a black box /functional testing technique </li></ul></ul><ul><ul><li>in determining a set of test cases, this technique is to partition the program domain into a (small) number of equivalent classes </li></ul></ul><ul><ul><li>the assumption is that if a representative element from a class is tested and passed, all other elements in the class need not to be tested assuming they would pass the test </li></ul></ul><ul><ul><li>How to define equivalent classes: </li></ul></ul><ul><ul><ul><li>if a input condition specifies a range , one valid and two invalid equivalent classes are defined </li></ul></ul></ul><ul><ul><ul><li>if an input condition requires a specific value , one valid and two invalid equivalent classes are defined </li></ul></ul></ul><ul><ul><ul><li>if an input condition specifies a member of a set , one valid and one invalid equivalent classes are defined </li></ul></ul></ul><ul><ul><ul><li>if an input condition is Boolean , one valid and one invalid class are defined </li></ul></ul></ul>
  18. 18. Techniques for Testing - Dynamic <ul><li>Equivalence Partitioning </li></ul><ul><ul><li>Example 1: Online banking </li></ul></ul><ul><ul><ul><li>The user can access the bank using his personal computer, providing a 6-digit password, and follow with a series of typed commands that trigger various banking functions. The software supplied for baking application accepts data in the form: </li></ul></ul></ul><ul><ul><ul><ul><li>area code: blank or three digit number not beginning with 0 or 1 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>password: six digit alphanumeric string </li></ul></ul></ul></ul><ul><ul><ul><ul><li>commands: “check”, “deposit”, or “bill pay” </li></ul></ul></ul></ul><ul><ul><ul><li>Equivalent classes can be identified for each field </li></ul></ul></ul><ul><ul><ul><ul><li>area code(boolean, range, specific value): </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>ec1: blank; ec2: 3-digit numbers (<200); ec3: 3-digit numbers (200-999); ec4: less than 3-digit numbers; ec5: more than 3-digit numbers (at least one value is needed for test case design) </li></ul></ul></ul></ul></ul>
  19. 19. Techniques for Testing - Dynamic <ul><li>Equivalence Partitioning </li></ul><ul><ul><ul><ul><li>password (boolean, specific value, set): </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>ec6: blank; ec7: 6-digit alphanumeric strings(valid passwords); ec8: 6-digit alphanumeric strings(invalid passwords); ec9: less than 6-digit alphanumeric strings; ec10: more than 6-digit alphanumeric strings </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><li>commands(boolean, set): </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>ec10: blank; ec11: valid (“check”, “deposit”, “bill pay”); ec12: invalid </li></ul></ul></ul></ul></ul><ul><ul><li>Example 2: an input condition “each book has a 6-digit number” (specific value) can be classified as either valid or invalid equivalent classes </li></ul></ul><ul><ul><ul><li>one valid class: 6-digit numbers </li></ul></ul></ul><ul><ul><ul><li>two invalid classes: more or less than 6 digits </li></ul></ul></ul><ul><ul><ul><li>test cases can be constructed to cover the three equivalent classes </li></ul></ul></ul><ul><ul><li>Weak point: partitioning may be inadequate so that the assumption may not hold </li></ul></ul>
  20. 20. Techniques for Testing - Dynamic <ul><li>Boundary Value Analysis (BVA) </li></ul><ul><ul><li>complements the equivalent class partitioning technique </li></ul></ul><ul><ul><li>Assumes software usually fails at boundaries. </li></ul></ul><ul><ul><li>concentrate on the extreme (boundary) values from each class (rather than random values from each class) </li></ul></ul><ul><ul><li>BVA leads to a selection of test cases that exercise bounding values </li></ul></ul><ul><ul><li>output can also be partitioned into equivalent classes, and extreme values from each class are tested as well </li></ul></ul><ul><ul><li>Guidelines for BVA: </li></ul></ul><ul><ul><ul><li>if an input condition specifies a range bounded by value a and b, test cases should be designed with values a and b, just above and just below a and b, respectively (a, b, --a, a++, --b, b++) </li></ul></ul></ul><ul><ul><ul><li>if an input condition specifies a number of values , test cases should be developed that exercise the minimum and maximum numbers. Values just above and below minimum and maximum are also tested </li></ul></ul></ul>
  21. 21. Techniques for Testing - Dynamic <ul><li>Boundary Value Analysis (BVA) </li></ul><ul><ul><ul><li>Apply guidelines 1 and 2 to output conditions . For example, assume that a temperature vs. pressure table is required as output from an engineering analysis program. Test cases should be designed to create an output report that produces the maximum (and minimum) allowable number of table entries. </li></ul></ul></ul><ul><ul><ul><li>If internal program data structures have prescribed boundaries (e.g., an array has a defined limit of 100 entries), be certain to design a test case to exercise that data structure at its boundary. </li></ul></ul></ul>
  22. 22. Techniques for Testing - Dynamic <ul><li>Basis Path Testing </li></ul><ul><ul><li>a white-box testing technique, proposed by Tom McCabe, 1976 </li></ul></ul><ul><ul><li>to derive a logical complexity measure of a procedural design, and use this measure as a guide for defining a basis set of execution paths </li></ul></ul><ul><ul><li>test cases derived to exercise every statement and branch in the program at least once during testing (statement/branch coverage) </li></ul></ul><ul><ul><li>if every condition in a compound condition is considered, condition coverage can be achieved </li></ul></ul><ul><ul><li>Steps: </li></ul></ul><ul><ul><ul><li>Draw a (control) flow graph , using the flowchart or the code </li></ul></ul></ul><ul><ul><ul><li>Calculate the cyclomatic complexity , using the flow graph </li></ul></ul></ul><ul><ul><ul><li>Determine the basis set of linearly independent paths </li></ul></ul></ul><ul><ul><ul><li>Design test cases to exercise each path in the basis set </li></ul></ul></ul>
  23. 23. Basis Path Testing <ul><li>Flow Graph </li></ul><ul><ul><li>used to depict program control structure </li></ul></ul><ul><ul><li>can be drawn from a flowchart (a procedural design representation) </li></ul></ul><ul><ul><li>can be drawn from a piece of source code </li></ul></ul><ul><ul><li>Flow Graph Notation </li></ul></ul><ul><ul><ul><li>a flow graph composed of edges and nodes </li></ul></ul></ul><ul><ul><ul><li>an edge starts from a node and ends to another node </li></ul></ul></ul><ul><ul><li>Sequence if-then-else While Repeat-until Case </li></ul></ul>
  24. 24. Basis Path Testing <ul><li>Flow Graph </li></ul><ul><ul><li>Draw a flow graph from source code </li></ul></ul><ul><ul><li>1 procedure insert(a, b, n, x) </li></ul></ul><ul><ul><li>2 begin bool found:=false; </li></ul></ul><ul><ul><li>3 for I:=1 to n do </li></ul></ul><ul><ul><li>4 if a[I]=x </li></ul></ul><ul><ul><li>5 then found:=true; goto leave endif </li></ul></ul><ul><ul><li>6 enddo; </li></ul></ul><ul><ul><li>7 leave: </li></ul></ul><ul><ul><li>8 if found </li></ul></ul><ul><ul><li>9 then b[I]:=b[I]+1 </li></ul></ul><ul><ul><li>10 else n:=n+1; a[n]:=x; b[n]:=1 endif </li></ul></ul><ul><ul><li>11 end insert </li></ul></ul>
  25. 25. Basis Path Testing <ul><li>Flow Graph </li></ul><ul><ul><li>Draw a flow graph from a flowchart </li></ul></ul>
  26. 26. Basis Path Testing <ul><li>Cyclomatic Complexity </li></ul><ul><ul><li>a software metric that provides a quantitative measure of the logical complexity of a program </li></ul></ul><ul><ul><li>Basis set: is a maximal linearly independent set of paths through a graph </li></ul></ul><ul><ul><li>An independent path: is any path through a program that introduces at least one new set of processing statements or a new condition (I.e. at least one new edge in a flow graph) </li></ul></ul><ul><ul><li>Cyclomatic complexity defines the number of independent path in the basis set of a program </li></ul></ul><ul><ul><li>gives an upper bound for the number of tests that must be conducted to achieve statement/branch/condition coverage </li></ul></ul><ul><ul><li>How to calculate cyclomatic complexity: </li></ul></ul><ul><ul><ul><ul><ul><li>cc = e - n + 2p </li></ul></ul></ul></ul></ul><ul><ul><li>e - number of edges; n - number of nodes; p - number of components; </li></ul></ul><ul><ul><li>if all nodes in a graph are connected, then p = 1, thus </li></ul></ul><ul><ul><ul><ul><ul><li>cc = e - n + 2 </li></ul></ul></ul></ul></ul>
  27. 27. Basis Path Testing: Example 1 <ul><li>1. Draw a flow graph </li></ul><ul><ul><li>0 /*Finding the maximum of three integers*/ </li></ul></ul><ul><ul><li>1 #include <stdio.h> </li></ul></ul><ul><ul><li>2 intmaximum(int, int, int); </li></ul></ul><ul><ul><li>3 main(){ </li></ul></ul><ul><ul><li>4 int a,b,c; </li></ul></ul><ul><ul><li>5 printf((“Enter three integers: “); </li></ul></ul><ul><ul><li>6 scanf(“%d%d%d”, &a,&b,&c); </li></ul></ul><ul><ul><li>7 printf(“Maximum is: %d ”, maximum(a,b,c)); </li></ul></ul><ul><ul><li>8 } </li></ul></ul><ul><ul><li>9 int maximum(int x, int y, int z){ </li></ul></ul><ul><ul><li>10 int max=x; </li></ul></ul><ul><ul><li>11 if(y>max) </li></ul></ul><ul><ul><li>12 max=y; </li></ul></ul><ul><ul><li>13 if(z>max) </li></ul></ul><ul><ul><li>14 max=z; </li></ul></ul><ul><ul><li>15 return max </li></ul></ul><ul><ul><li>16 } </li></ul></ul>==>
  28. 28. Basis Path Testing: Example 1 <ul><li>2. Calculate cyclomatic complexity </li></ul><ul><ul><li>e=7, n=6, p=1; so that cc=7-6+2=3 </li></ul></ul><ul><li>3. Identify a basis set of independent paths </li></ul><ul><ul><li>p1: a-b-c-d-e-f (y>x, z>y) </li></ul></ul><ul><ul><li>p2: a-b-d-e-f (y<=x, z>x) </li></ul></ul><ul><ul><li>p3: a-b-c-d-f (y>x, z<=y) </li></ul></ul><ul><li>4. Design test cases </li></ul>
  29. 29. Basis Path Testing: Example 2 <ul><li>1. Draw a flow graph </li></ul><ul><ul><li>see slide 6-24: source code, flow graph </li></ul></ul><ul><li>2. Calculate cyclomatic complexity </li></ul><ul><ul><li>e = 12; n = 10; p = 1 </li></ul></ul><ul><ul><li>cc = 12 - 10 + 2 x 1 =4 </li></ul></ul><ul><li>3. Determine a basis set of independent paths </li></ul><ul><ul><li>expect to specify 4 independent paths </li></ul></ul><ul><ul><li>p1: 1-2-3-7-8-9-11 </li></ul></ul><ul><ul><li>p2: 1-2-3- 4-5 -7-8-9-11 </li></ul></ul><ul><ul><li>p3: 1-2-3-4-5-7-8- 10 -11 </li></ul></ul><ul><ul><li>p4: 1-2- 3-4- 6 -3 -7-8-10-11 ( 1 or more times ) </li></ul></ul><ul><ul><li>HOWEVER: by reading source code, we found </li></ul></ul><ul><ul><ul><li>3-7 => 10; 5 => 9 </li></ul></ul></ul><ul><ul><ul><li>p1 and p3 must be modified </li></ul></ul></ul>
  30. 30. Basis Path Testing: Example 2 <ul><li>3. Determine a basis set of independent paths </li></ul><ul><ul><ul><li>if p3 modified, it would be the same as p2. Thus p3 should be deleted. </li></ul></ul></ul><ul><ul><ul><li>But the new paths introduced by p3 (8-10-11) must be covered by other paths! We found p4 covers them. </li></ul></ul></ul><ul><ul><ul><li>Modify p1, delete p3, we can have three independent paths </li></ul></ul></ul><ul><ul><ul><ul><li>p1: 1-2-3-7-8-10-11 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>p2: 1-2-3-4-5-7-8-9-11 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>p3: 1-2-3-4-6-3-7-8-10-11 </li></ul></ul></ul></ul><ul><ul><ul><li>if you study the program carefully, you will find the following is better </li></ul></ul></ul><ul><ul><ul><ul><li>p1: 1-2-3-7-8-10-11 (insert x when a[] is empty) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>p2: 1-2-3-4-5-7-8-9-11(insert x when a[1]=x) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>p3: 1-2- 3-4-6-3 -4-5-7-8-9-11 (insert x when a[i]=x,i>1, n>=i) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>p4: 1-2- 3-4-6-3 -7-8-10-11 (insert x when a[] is not empty and x is not in a[]; p4 does not introduce any new edge but it exercises a new combination of the program logic!) </li></ul></ul></ul></ul>
  31. 31. Basis Path Testing: Example 2 <ul><li>4. Design test cases </li></ul><ul><ul><li>Path 1 test case: 1-2-3-7-8-10-11 (insert x when a[] is empty) </li></ul></ul><ul><ul><ul><li>input data: n=0; x=8; a[1]=0; b[1]=0; </li></ul></ul></ul><ul><ul><ul><li>expected results: a[1]=8; b[1]=1; n=1; </li></ul></ul></ul><ul><ul><li>Path 2 test case: 1-2-3-4-5-7-8-9-11(insert x when a[1]=x) </li></ul></ul><ul><ul><ul><li>input data: n=3; x=9; a[1]=9; a[2]=2; a[3]=3;b[1]=2;b[2]=5;b[3]=8; </li></ul></ul></ul><ul><ul><ul><li>expected results: b[1]=3 </li></ul></ul></ul><ul><ul><li>Path 3 test case: 1-2- 3-4-6-3 -4-5-7-8-9-11 (insert x when a[i]=x,i>1, n>=i) </li></ul></ul><ul><ul><ul><li>input data: n=3;x=3;a[1]=9;a[2]=2;a[3]=3;b[1]=3;b[2]=2;b[3]=8; </li></ul></ul></ul><ul><ul><ul><li>expected results: b[3]=9 </li></ul></ul></ul><ul><ul><li>Path 4 test case: 1-2- 3-4-6-3 -7-8-10-11 (insert x when a[] is not empty and x is not in a[]) </li></ul></ul><ul><ul><ul><li>input data: n=3;x=6;a[1]=9;a[2]=2;a[3]=3;b[1]=3;b[2]=2;b[3]=8; </li></ul></ul></ul><ul><ul><ul><li>expected results: a[4]=6; b[4]=1; n=4; </li></ul></ul></ul>
  32. 32. Techniques for Testing - Dynamic <ul><li>Loop Testing </li></ul><ul><ul><li>a white box/structural testing technique </li></ul></ul><ul><ul><li>focuses exclusively on the validity of loop constructs </li></ul></ul><ul><ul><li>four different classes of loops can be defined: </li></ul></ul><ul><ul><li>simple loops nested loops concatenated loops unconstructed loops </li></ul></ul>
  33. 33. Techniques for Testing - Dynamic <ul><li>Loop Testing </li></ul><ul><ul><li>simple loops </li></ul></ul><ul><ul><ul><li>if n is the maximum number of allowable passes through the loop </li></ul></ul></ul><ul><ul><ul><li>the following set of test cases (7 cases) can be applied </li></ul></ul></ul><ul><ul><ul><ul><li>skip the loop entirely (0) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>only one pass through the loop (1) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>two passes through the loop (2) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>m passes through the loop where m<n (m) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>n-1, n, n+1 passes through the loop (n-1, n, n+1) </li></ul></ul></ul></ul><ul><ul><ul><li>Class Exercise </li></ul></ul></ul><ul><ul><ul><ul><li>use the example for the basis path testing to derive 7 test cases </li></ul></ul></ul></ul><ul><ul><ul><ul><li>for real testing, you need to write a program to test the function </li></ul></ul></ul></ul>
  34. 34. Techniques for Testing - Dynamic <ul><li>Loop Testing </li></ul><ul><ul><li>nested loops </li></ul></ul><ul><ul><ul><li>start at the innermost loop. Set all other loops to minimum values </li></ul></ul></ul><ul><ul><ul><li>conduct simple loop tests for the innermost loop while holding the outer loops at their minimum iteration parameter values. </li></ul></ul></ul><ul><ul><ul><li>Work outward, conducting tests for the next loop, but keeping all other outer loops at minimum values and other nested loops to “typical” values </li></ul></ul></ul><ul><ul><ul><li>continue until all loops have been tested </li></ul></ul></ul><ul><ul><li>concatenated loops </li></ul></ul><ul><ul><ul><li>if concatenated loops are independent, use the approach defined for simple loops </li></ul></ul></ul><ul><ul><ul><li>if not independent(the loop counter for loop 1 is used as the initial value for loop 2), then the approach applied to nested loops is recommended </li></ul></ul></ul>
  35. 35. Techniques for Testing - Dynamic <ul><li>Testing Coverage </li></ul><ul><ul><li>Statement coverage - Run a series of tests which ensure that every statement is tested at least once. A tool is used to keep track of how many times a statement has been executed. BUT - not every situation is dealt with! </li></ul></ul><ul><ul><li>Branch coverage - Run a series of tests that ensure that every possible branch is tested at least once. Again a tool is required. </li></ul></ul><ul><ul><li>Condition coverage - Run a series of tests that ensure that every possible outcome of each condition is tested at least once. </li></ul></ul><ul><ul><li>Path Coverage - Run a series of tests that cover all possible combination of paths. This may be impossible so paths have to be selected </li></ul></ul><ul><ul><li>All-definition-use-path coverage - Create a test case for all paths that lead from a definition e.g. x=1 to a variable x = x +1. </li></ul></ul>
  36. 36. Further Test Stages <ul><li>So far we have dealt with module testing or unit testing </li></ul><ul><li>Integration Testing </li></ul><ul><ul><li>Modules need to be tested when combined </li></ul></ul><ul><ul><li>Start with low level modules and move up </li></ul></ul><ul><ul><ul><li>difficult to get an impression of the overall system </li></ul></ul></ul><ul><ul><li>Start at the top and work down to subsystems </li></ul></ul><ul><ul><ul><li>may prove repetitive and laborious </li></ul></ul></ul><ul><ul><li>A combination of both approaches can be used </li></ul></ul><ul><li>System Test : Testing the whole system </li></ul><ul><li>Acceptance Test : Testing the usability </li></ul><ul><li>Installation Test: If the operating environment is different from the development environment </li></ul>