Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Software Testing Objectives and principles Techniques Process Object-oriented testing Test workbenches and frameworks
  2. 2. Lecture Objectives <ul><li>Understand </li></ul><ul><ul><li>Software testing objectives and principles </li></ul></ul><ul><ul><li>Testing techniques – black-box and white-box </li></ul></ul><ul><ul><li>Testing process – unit and integration </li></ul></ul><ul><ul><li>Object-oriented testing </li></ul></ul><ul><ul><li>Test workbenches and frameworks </li></ul></ul>
  3. 3. Can We Exhaustively Test Software? <ul><li>There are 250 billion unique paths between A and B. </li></ul><ul><li>If each set of possible data is used, and a single run takes 1 millisecond to execute, it would take 8 years to test all paths. </li></ul>A B
  4. 4. Can we test all types of software bugs? <ul><li>Software testing is mainly suitable for dealing with faults that consistently define themselves under well defined conditions </li></ul><ul><li>Testers do encounter failures they can’t reproduce. </li></ul><ul><ul><li>Under seemingly exact conditions, the actions that a test case specifies can sometimes, but not always, lead to a failure </li></ul></ul><ul><ul><li>Software engineers sometimes refer to faults with this property as Mandelbugs (an allusion to Benoit Mandelbrot, a leading researcher in fractal geometry) </li></ul></ul><ul><li>Example: the software fault in the Patriot missile defense system responsible for the Scud incident in Dhahran </li></ul><ul><ul><li>To project a target’s trajectory, the weapons control computer required its velocity and the time as real values </li></ul></ul><ul><ul><li>The system, however, kept time internally as an integer, counting tenths of seconds and storing them in a 24 bit register </li></ul></ul><ul><ul><li>The necessary conversion into a real value caused imprecision in the calculated range where a detected target was expected next </li></ul></ul><ul><ul><li>For a given velocity of the target, these inaccuracies were proportional to the length of time the system had been continuously running </li></ul></ul>
  5. 5. Testing Objectives <ul><li>Software testing can show the presence of bugs, but it can never show their absence. Therefore, </li></ul><ul><ul><li>Testing is the process of exercising a program with the specific intent of finding errors prior to delivery to the end user. </li></ul></ul><ul><ul><li>A good test case is one that has a high probability of finding an error. </li></ul></ul><ul><ul><li>A successful test is one that uncovers an error. </li></ul></ul>
  6. 6. Testing Principles <ul><li>All tests should be traceable to customer requirements </li></ul><ul><li>Tests should be planned long before testing begins </li></ul><ul><li>The Pareto principle applies to software testing </li></ul><ul><li>Testing should begin “in the small” and progress toward testing “in the large” </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>
  7. 7. Test Case Design <ul><li>Testing must be planned and performed systematically…not ad hoc or random. </li></ul><ul><li>Testing can be performed in two ways: </li></ul><ul><ul><li>Knowing the specified function that a product has been designed to perform – black-box testing. </li></ul></ul><ul><ul><li>Knowing the internal workings of the product and testing to ensure all parts are exercised adequately – white-box testing. </li></ul></ul>
  8. 8. Black-box Testing <ul><li>An approach to testing where the program is considered as a ‘black-box’ </li></ul><ul><li>The program test cases are based on the system specification </li></ul><ul><li>Test planning can begin early in the software process </li></ul>
  9. 9. Equivalence Partitioning <ul><li>Divide the input domain into classes of data from which test cases can be derived. </li></ul><ul><li>Strives to define a test that uncovers classes of errors – reducing total number of test cases required. </li></ul>
  10. 10. Example… <ul><li>Specifications for DBMS state that product must handle any number of records between 1 and 16,383 (2 14 –1) </li></ul><ul><li>If system can handle 34 records and 14,870 records, then probably will work fine for 8,252 records, say. </li></ul><ul><li>If system works for any one test case in range (1..16,383), then it will probably work for any other test case in range </li></ul><ul><li>Range (1..16,383) constitutes an equivalence class </li></ul><ul><ul><li>Any one member is as good a test case as any other member of the class </li></ul></ul>
  11. 11. … Example <ul><li>Range (1..16,383) defines three different equivalence classes: </li></ul><ul><ul><li>Equivalence Class 1: Fewer than 1 record </li></ul></ul><ul><ul><li>Equivalence Class 2: Between 1 and 16,383 records </li></ul></ul><ul><ul><li>Equivalence Class 3: More than 16,383 records </li></ul></ul>
  12. 12. Boundary Value Analysis <ul><li>Technique that leads to selection of test cases that exercise bounding values. </li></ul><ul><li>Selecting test case on or just to one side of boundary of equivalence class increases probability of detecting fault. </li></ul>&quot;Bugs lurk in corners and congregate at boundaries&quot;
  13. 13. DBMS Example <ul><li>Test case 1: 0 records Member of equivalence class 1 (& adjacent to boundary value) </li></ul><ul><li>Test case 2: 1 record Boundary value </li></ul><ul><li>Test case 3: 2 records Adjacent to boundary value </li></ul><ul><li>Test case 4: 723 records Member of equivalence class 2 </li></ul><ul><li>Test case 5: 16,382 records Adjacent to boundary value </li></ul><ul><li>Test case 6: 16,383 records Boundary value </li></ul><ul><li>Test case 7: 16,384 records Member of equivalence class 3 (& adjacent to boundary value) </li></ul>
  14. 14. White-box Testing <ul><li>Test case design method that uses the control structure of the procedural design to derive test cases. </li></ul><ul><li>Can derive tests that: </li></ul><ul><ul><li>Guarantee all independent paths have been exercised at least once </li></ul></ul><ul><ul><li>Exercise all logical decisions on their true and false sides </li></ul></ul><ul><ul><li>Execute all loops at their boundaries and within operational bounds </li></ul></ul><ul><ul><li>Exercise internal data structures to ensure validity </li></ul></ul>
  15. 15. Basis Path Testing <ul><li>Proposed by Tom McCabe. </li></ul><ul><li>Use cyclomatic complexity measure as guide for defining a basis set of execution paths. </li></ul><ul><li>Test cases derived to exercise the basis set are guaranteed to execute every statement at least once. </li></ul>
  16. 16. <ul><li>CC = 5 </li></ul><ul><li>So 5 independent paths </li></ul><ul><ul><li>a, c, f </li></ul></ul><ul><ul><li>a, d, c, f </li></ul></ul><ul><ul><li>a, b, e, f </li></ul></ul><ul><ul><li>a, b, e, a, … </li></ul></ul><ul><ul><li>a, b, e, b, e, … </li></ul></ul>Independent Paths a b c d e f
  17. 17. The Flowgraph <ul><li>Before the cyclomatic complexity can be calculated, and the paths determined, the flowgraph must be created. </li></ul><ul><li>Done by translating the source code into flowgraph notation: </li></ul>sequence if while until case
  18. 18. Example <ul><li>PROCEDURE average </li></ul><ul><li>INTERFACE RETURNS average, total.input, total.valid; </li></ul><ul><li>INTERFACE ACCEPTS value, minimum, maximum; </li></ul><ul><li>TYPE value[1:100] IS SCALAR ARRAY; </li></ul><ul><li>TYPE average, total.input, total.valid; </li></ul><ul><li>minimum, maximum, sum IS SCALAR; </li></ul><ul><li>TYPE i IS INTEGER; </li></ul><ul><li>i = 1; </li></ul><ul><li>total.input = total.valid = 0; </li></ul><ul><li>sum = 0; </li></ul><ul><li>DO WHILE value[i] <> -999 AND total.input < 100 </li></ul><ul><li>increment total.input by 1; </li></ul><ul><li>IF value[i] >= minimum AND value[1] <= maximum </li></ul><ul><li>THEN increment total.valid by 1; </li></ul><ul><li> sum = sum + value[i] </li></ul><ul><li>ELSE skip </li></ul><ul><li>ENDIF </li></ul><ul><li>increment i by 1; </li></ul><ul><li>ENDDO </li></ul><ul><li>IF total.valid > 0 </li></ul><ul><li>THEN average = sum/total.valid; </li></ul><ul><li>ELSE average = -999; </li></ul><ul><li>ENDIF </li></ul><ul><li>END average </li></ul>1 2 3 4 5 6 7 8 9 10 11 12 13
  19. 19. … Example <ul><li>Flowgraph for average </li></ul><ul><li>Determine the: </li></ul><ul><li>Cyclomatic complexity </li></ul><ul><li>Independent paths </li></ul>1 2 3 4 5 6 10 13 12 11 7 8 9
  20. 20. Condition Testing <ul><li>Exercises logical conditions contained within a program module. </li></ul><ul><li>Types of errors found include; </li></ul><ul><ul><li>Boolean operator error (OR, AND, NOT) </li></ul></ul><ul><ul><li>Boolean variable error </li></ul></ul><ul><ul><li>Boolean parenthesis error </li></ul></ul><ul><ul><li>Relational operator error (>,<,=,!=,…) </li></ul></ul><ul><ul><li>Arithmetic expression error </li></ul></ul>
  21. 21. Loop Testing <ul><li>Focus exclusively on the validity of loop constructs. </li></ul><ul><li>4 types of loop can be defined: </li></ul><ul><ul><li>Simple </li></ul></ul><ul><ul><li>Nested </li></ul></ul><ul><ul><li>Concatenated </li></ul></ul><ul><ul><li>Unstructured </li></ul></ul>
  22. 22. Loop Types Simple Concatenated Nested Unstructured
  23. 23. Simple Loops <ul><li>Where n is the max number of passes, the following test can be applied: </li></ul><ul><ul><li>Skip loop entirely </li></ul></ul><ul><ul><li>Only one pass </li></ul></ul><ul><ul><li>2 passes </li></ul></ul><ul><ul><li>m passes (where m < n ) </li></ul></ul><ul><ul><li>n -1, n , n +1 passes </li></ul></ul>
  24. 24. Nested Loops <ul><li>If the approach for simple loops is extended, number of possible tests would grow geometrically – impractical. </li></ul><ul><li>Instead: </li></ul><ul><ul><li>Start at innermost loop. Set all other loops to minimum values. </li></ul></ul><ul><ul><li>Conduct simple loop test for innermost loop while holding outer loops at minimum loop counter values. Add other test for out-of-range or excluded values. </li></ul></ul><ul><ul><li>Work outward, conducting tests for next loop, but keeping all other outer lops at minimum values and other nested loops to ‘typical’ values. </li></ul></ul><ul><ul><li>Continue until all loops tested. </li></ul></ul>
  25. 25. Concatenated Loops <ul><li>Test as simple loops provided each loop is independent. </li></ul><ul><li>If two loops are concatenated and loop counter for loop 1 is used as initial value for loop 2, then test as nested loops. </li></ul>
  26. 26. Unstructured Loops <ul><li>Can’t test unstructured loops effectively. </li></ul><ul><li>Reflects very bad practice and should be redesigned. </li></ul>
  27. 27. The Tester <ul><li>Who does the testing? </li></ul><ul><ul><li>Developer </li></ul></ul><ul><ul><li>Member of development team </li></ul></ul><ul><ul><li>SQA </li></ul></ul><ul><ul><li>All of the above </li></ul></ul>
  28. 28. Independent Test Group <ul><li>Strictly speaking, testing should be performed by an independent group (SQA or 3 rd party) </li></ul><ul><li>Members of the development team are inclined to be more interested in meeting the rapidly-approaching due-date. </li></ul><ul><li>The developer of the code is prone to test “gently”. </li></ul><ul><li>Must remember that the objective is to find errors, not to complete test without finding them (because they’re always there!) </li></ul>
  29. 29. Successful Testing <ul><li>The success of testing can be measured by applying a simple metric: </li></ul><ul><li>So as defect removal efficiency approaches 1, process approaches perfection. </li></ul>
  30. 30. The Testing Process <ul><li>Unit testing </li></ul><ul><ul><li>Testing of individual program components </li></ul></ul><ul><ul><li>Often performed by the component developer </li></ul></ul><ul><ul><li>Tests often derived from the developer’s experience! </li></ul></ul><ul><ul><li>Increased productivity possible with xUnit framework </li></ul></ul><ul><li>Integration testing </li></ul><ul><ul><li>Testing of groups of components integrated to create a system or sub-system </li></ul></ul><ul><ul><li>The responsibility of an independent testing team </li></ul></ul><ul><ul><li>Tests are based on a system specification </li></ul></ul>
  31. 31. Testing Phases Unit testing Integration testing Software developer Development team/ SQA/ Independent Test Group
  32. 32. Integration Testing <ul><li>Tests complete systems or subsystems composed of integrated components </li></ul><ul><li>Integration testing should be black-box testing with tests derived from the specification </li></ul><ul><li>Main difficulty is localizing errors </li></ul><ul><li>Incremental integration testing reduces this problem </li></ul>
  33. 33. Incremental Integration Testing
  34. 34. Approaches to Integration Testing <ul><li>Top-down testing </li></ul><ul><ul><li>Start with high-level system and integrate from the top-down replacing individual components by stubs where appropriate </li></ul></ul><ul><li>Bottom-up testing </li></ul><ul><ul><li>Integrate individual components in levels until the complete system is created </li></ul></ul><ul><li>In practice, most integration involves a combination of these strategies </li></ul>
  35. 35. Top-down Testing
  36. 36. Bottom-up Testing
  37. 37. Which is Best? <ul><li>In bottom-up testing: </li></ul><ul><ul><li>Test harnesses must be constructed and this takes time. </li></ul></ul><ul><ul><li>Integration errors are found later rather than earlier. </li></ul></ul><ul><ul><li>Systems-level design flaws that could require major reconstruction are found last. </li></ul></ul><ul><ul><li>There is no visible, working system until the last stage so is harder to demonstrate progress to clients. </li></ul></ul>
  38. 38. <ul><li>Takes place when modules or sub-systems are integrated to create larger systems </li></ul><ul><li>Objectives are to detect faults due to interface errors or invalid assumptions about interfaces </li></ul><ul><li>Particularly important for object-oriented development as objects are defined by their interfaces </li></ul>Interface Testing
  39. 39. Interface Testing
  40. 40. Interfaces Types <ul><li>Parameter interfaces </li></ul><ul><ul><li>Data passed from one procedure to another </li></ul></ul><ul><li>Shared memory interfaces </li></ul><ul><ul><li>Block of memory is shared between procedures </li></ul></ul><ul><li>Procedural interfaces </li></ul><ul><ul><li>Sub-system encapsulates a set of procedures to be called by other sub-systems </li></ul></ul><ul><li>Message passing interfaces </li></ul><ul><ul><li>Sub-systems request services from other sub-systems </li></ul></ul>
  41. 41. Interface Errors <ul><li>Interface misuse </li></ul><ul><ul><li>A calling component calls another component and makes an error in its use of its interface e.g. parameters in the wrong order </li></ul></ul><ul><li>Interface misunderstanding </li></ul><ul><ul><li>A calling component embeds assumptions about the behaviour of the called component which are incorrect </li></ul></ul><ul><li>Timing errors </li></ul><ul><ul><li>The called and the calling component operate at different speeds and out-of-date information is accessed </li></ul></ul>
  42. 42. Interface Testing Guidelines <ul><li>Design tests so that parameters to a called procedure are at the extreme ends of their ranges </li></ul><ul><li>Always test pointer parameters with null pointers </li></ul><ul><li>Use stress testing in message passing systems </li></ul><ul><li>In shared memory systems, vary the order in which components are activated </li></ul><ul><li>Design tests which cause the component to fail </li></ul>
  43. 43. Stress Testing <ul><li>Exercises the system beyond its maximum design load. </li></ul><ul><ul><li>Stressing the system often causes defects to come to light </li></ul></ul><ul><li>Stressing the system test failure behaviour. </li></ul><ul><ul><li>Systems should not fail catastrophically. Stress testing checks for unacceptable loss of service or data </li></ul></ul><ul><li>Particularly relevant to distributed systems which can exhibit severe degradation as a network becomes overloaded </li></ul>
  44. 44. <ul><li>The components to be tested are object classes that are instantiated as objects </li></ul><ul><li>Larger grain than individual functions so approaches to white-box testing have to be extended </li></ul><ul><li>No obvious ‘top’ to the system for top-down integration and testing </li></ul>Object-Oriented Testing
  45. 45. Testing Levels <ul><li>Test object classes </li></ul><ul><li>Test clusters of cooperating objects </li></ul><ul><li>Test the complete OO system </li></ul>
  46. 46. Object Class Testing <ul><li>Complete test coverage of a class involves </li></ul><ul><ul><li>Testing all operations associated with an object </li></ul></ul><ul><ul><li>Setting and interrogating all object attributes </li></ul></ul><ul><ul><li>Exercising the object in all possible states </li></ul></ul><ul><li>Inheritance makes it more difficult to design object class tests as the information to be tested is not localized </li></ul>
  47. 47. Object Integration <ul><li>Levels of integration are less distinct in object-oriented systems </li></ul><ul><li>Cluster testing is concerned with integrating and testing clusters of cooperating objects </li></ul><ul><li>Identify clusters using knowledge of the operation of objects and the system features that are implemented by these clusters </li></ul>
  48. 48. Approaches to Cluster Testing <ul><li>Use-case or scenario testing </li></ul><ul><ul><li>Testing is based on a user interactions with the system </li></ul></ul><ul><ul><li>Has the advantage that it tests system features as experienced by users </li></ul></ul><ul><li>Thread testing </li></ul><ul><ul><li>A thread consists of all the classes needed to respond to a single external input. Each class is unit tested, and then the thread set is exercised. </li></ul></ul><ul><li>Object interaction testing </li></ul><ul><ul><li>Tests sequences of object interactions that stop when an object operation does not call on services from another object </li></ul></ul><ul><li>Uses-based testing </li></ul><ul><ul><li>Begins by testing classes that use few or no server classes. Next, classes that use the first group of classes are tested, followed by classes that use the second group, and so on. </li></ul></ul>
  49. 49. Scenario-Based Testing <ul><li>Identify scenarios from use-cases and supplement these with interaction diagrams that show the objects involved in the scenario </li></ul><ul><li>Consider the scenario in the weather station system where a report is generated </li></ul>
  50. 50. Collect Weather Data
  51. 51. Weather Station Testing <ul><li>Thread of methods executed </li></ul><ul><ul><li>CommsController:request  WeatherStation:report  WeatherData:summarize </li></ul></ul><ul><li>Inputs and outputs </li></ul><ul><ul><li>Input of report request with associated acknowledge and a final output of a report </li></ul></ul><ul><ul><li>Can be tested by creating raw data and ensuring that it is summarized properly </li></ul></ul><ul><ul><li>Use the same raw data to test the WeatherData object </li></ul></ul>
  52. 52. OO Testing: Myths & Reality <ul><li>Inheritance means never having to say your sorry </li></ul><ul><li>Reuse means never having to say your sorry </li></ul><ul><li>Black box testing is sufficient </li></ul>
  53. 53. Implications of Inheritance <ul><li>Myth: </li></ul><ul><ul><li>specializing from tested superclasses means subclasses will be correct </li></ul></ul><ul><li>Reality: </li></ul><ul><ul><li>Subclasses create new ways to misuse inherited features </li></ul></ul><ul><ul><ul><li>Different test cases needed for each context </li></ul></ul></ul><ul><ul><ul><li>Need to retest inherited methods, even if unchanged. </li></ul></ul></ul>
  54. 54. Implications of Reuse <ul><li>Myth: </li></ul><ul><ul><li>Reusing a tested class means that the behavior of the server object is trustworthy </li></ul></ul><ul><li>Reality: </li></ul><ul><ul><li>Every new usage provides ways to misuse a server. </li></ul></ul><ul><ul><ul><li>Even if many server object of a given class function correctly, nothing is to prevent a new client class from using it incorrectly </li></ul></ul></ul><ul><ul><ul><li>we can't automatically trust a server because it performs correctly for one client </li></ul></ul></ul>
  55. 55. Implication of Encapsulation <ul><li>Myth: </li></ul><ul><ul><li>White-box testing violates encapsulation, surely black-box testing (of class interfaces) is sufficient. </li></ul></ul><ul><li>Reality: </li></ul><ul><ul><li>Studies indicate that “thorough” BBT sometimes exercises only 1/3 of code. </li></ul></ul><ul><ul><li>BBT exercises all specified behaviors, what about unspecified behaviors?! </li></ul></ul><ul><ul><ul><li>Need to examine implementation. </li></ul></ul></ul>
  56. 56. And What About Polymorphism? <ul><li>Each possible binding of a polymorphic component requires separate test…probably separate test case! </li></ul>
  57. 57. Testing Workbenches <ul><li>Testing is an expensive process phase. Testing workbenches provide a range of tools to reduce the time required and total testing costs </li></ul><ul><li>Most testing workbenches are open systems because testing needs are organization-specific </li></ul><ul><li>Difficult to integrate with closed design and analysis workbenches </li></ul>
  58. 58. A Testing Workbench
  59. 59. Workbench Components <ul><li>Test manager : manages the running of program tests </li></ul><ul><li>Test data generator : selects test data from database or uses patterns to generate random data of correct form </li></ul><ul><li>Oracle : Predicts expected results (may be previous version/prototype) </li></ul><ul><li>Comparator : compare results of oracle and program, or program and previous version (regression test) </li></ul><ul><li>Dynamic analyzer : counts number of times each statement is executed during test. </li></ul><ul><li>Simulator : simulates environment (target platform, user interaction, etc) </li></ul>
  60. 60. xUnit Framework <ul><li>Developed by Kent Beck </li></ul><ul><li>Makes object-oriented unit testing more accessible. </li></ul><ul><li>Freeware versions available for most object-oriented languages </li></ul><ul><ul><li>www.xprogramming.com/software.htm </li></ul></ul>
  61. 61. jUnit – “successful”
  62. 62. jUnit – “unsuccessful”
  63. 63. Simple Guide to Using xUnit <ul><li>Subclass TestCase class for the object under test </li></ul><ul><ul><li>Ensure test class has scope over object under test. </li></ul></ul><ul><li>Add a test method to the test class for each method. </li></ul><ul><ul><li>An xUnit test method is an ordinary method without parameters. </li></ul></ul><ul><li>Code the test case in the test method </li></ul><ul><ul><li>Creates objects necessary for the test (fixture) (1) </li></ul></ul><ul><ul><li>Exercises objects in the fixture (2) </li></ul></ul><ul><ul><li>Verifies the result. (3) </li></ul></ul>
  64. 64. Key Points <ul><li>Exhaustive testing is not possible </li></ul><ul><li>Testing must be done systematically using black-box and white-box testing techniques </li></ul><ul><li>Testing must be done at both unit and integration levels </li></ul><ul><li>Object-oriented programming offers its own challenges for testing </li></ul><ul><li>Testing workbenches and frameworks can help with the testing process </li></ul>
  65. 65. References <ul><li>M. Grottke and K.S. Trivedi. Fighting Bugs: Remove, Retry, Replicate and Rejuvinate. IEEE Computer , February 2007, pp. 107 – 109. </li></ul><ul><li>R. Pressman. Software Engineering: A Practitioners Approach , New York, NY: McGraw-Hill, 6 th Ed, 2004. </li></ul><ul><li>I. Sommerville. Software Engineering , 6 th Ed. New York, NY: Addison-Wesley, 2000. </li></ul>