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.



Published on

  • Be the first to comment

  • Be the first to like this


  1. 1. Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung The University of Texas at Arlington and Advanced Software International Corporation Arlington, Texas 76019-0015 817-272-3785 [email_address]
  2. 2. Overview of Presentation <ul><li>Why Object-Oriented Software Testing </li></ul><ul><li>The State-of-the-Research </li></ul><ul><li>OO Software Testing Research at UTA </li></ul><ul><li>OOTWorks Software Demonstration </li></ul>
  3. 3. Why Object-Oriented Software Testing <ul><li>transition to OO development is not easy </li></ul><ul><ul><li>OO conceptualization, design and programming significantly impact the quality </li></ul></ul><ul><ul><li>many developers’ mindset is still in procedural design and programming </li></ul></ul><ul><ul><li>anti-design patterns are commonly found in OO design and OO code </li></ul></ul>
  4. 4. Case Study 1: Analysis of a Fedex Ship Manager Software <ul><li>This software was designed and implemented by a team of students taking an OO software engineering class </li></ul><ul><li>It has nothing to do with Fedex </li></ul><ul><li>The software was supposed to compute and display the shipment charges for all Fedex services from a given origin zip to a given destination zip </li></ul><ul><li>This program is working but it has some design problems </li></ul><ul><li>We show how OOTWorks can be used to detect these design problems </li></ul>
  5. 5. Poor Conceptualization NextAfternoon, OvernightExpress, Ground, etc. are services. They are not a RateChart. It is better to use association.
  6. 6. Poor Responsibility Assignment There should not be a class called “RateCalculator”. The services are the “experts” who know how to calculate their own rates. This design assigns the responsibility to the wrong object.
  7. 7. Incorrect Use of Inheritance Child classes must not repeat the same code as the parent class, failing to utilize the inheritance and polymorphism features. This increases the maintenance effort.
  8. 8. Better Design Better conceptualization. The services use ZoneChart and Delivery Area Surcharge to calculate rates.
  9. 9. Better Design The subclasses inherit and use all of the methods of the superclass.
  10. 10. Automatic Design Improvement The repeated code can be deleted from the subclasses.
  11. 11. Automatic Design Improvement
  12. 12. Why Object-Oriented Software Testing <ul><li>OO features introduce new testing problems </li></ul><ul><ul><li>encapsulation leading to long method invocation chains, more difficulty to understand the (overall) functionality </li></ul></ul><ul><ul><li>inheritance and polymorphism: which method to execute is determined at run time </li></ul></ul><ul><ul><li>multiple and/or repeated inheritance may cause incorrect interaction in child classes </li></ul></ul><ul><ul><li>you cannot test a class, you can only test instances of a class </li></ul></ul>
  13. 13. Invocation chains in the InterViews Library: 122 classes, >400 relationships Chain Length Number of Chains
  14. 14. Why Object-Oriented Software Testing main () { Shape *p; … . p->print(); // which print() to // execute? … } Shape print () Box print () Square print ()
  15. 15. <ul><li>objects engage in complex interdependent relationships </li></ul><ul><ul><li>testing one object may require test stubs to simulate other objects </li></ul></ul><ul><ul><li>test stubs construction is costly and time consuming </li></ul></ul><ul><ul><li>mutual or cyclic dependencies introduce additional complexity and costs in unit and integration testing </li></ul></ul><ul><ul><li>need a test order for unit testing and integration testing </li></ul></ul>Why Object-Oriented Software Testing
  16. 16. Complex Relationships
  17. 17. <ul><li>objects exhibit strong state dependent behaviors </li></ul><ul><ul><li>how to identify states and transitions? </li></ul></ul><ul><ul><li>how to identify state dependent interactions? </li></ul></ul><ul><ul><li>how to generate test cases to test state behaviors? </li></ul></ul><ul><ul><li>how to reduce the complexity of state behavior testing? </li></ul></ul>Why Object-Oriented Software Testing
  18. 18. The State-of-the-Research <ul><li>OO software testing began in the 1990s </li></ul><ul><li>A number of test methods and techniques have been proposed </li></ul><ul><li>There are various tools, some are free some are not </li></ul><ul><li>The tester still has to do a lot of work </li></ul>
  19. 19. The State-of-the-Research <ul><li>OO Test Methods and Techniques </li></ul><ul><ul><li>incremental testing of class hierarchy </li></ul></ul><ul><ul><li>test order </li></ul></ul><ul><ul><li>object state testing </li></ul></ul><ul><ul><li>class testing, cluster testing </li></ul></ul><ul><ul><li>data flow analysis </li></ul></ul><ul><ul><li>testing polymorphic relationships </li></ul></ul><ul><ul><li>data flow analysis for exception handling mechanism </li></ul></ul><ul><ul><li>OO regression testing </li></ul></ul>
  20. 20. OO Software Testing Research at UTA <ul><li>A reverse engineering technology </li></ul><ul><li>Plus a set of utilities to facilitate </li></ul><ul><ul><li>program understanding </li></ul></ul><ul><ul><li>design documentation </li></ul></ul><ul><ul><li>design analysis </li></ul></ul><ul><ul><li>design improvement </li></ul></ul><ul><ul><li>metrics calculation </li></ul></ul><ul><ul><li>test scheduling </li></ul></ul><ul><ul><li>change impact analysis </li></ul></ul><ul><ul><li>version comparison </li></ul></ul><ul><ul><li>test case generation </li></ul></ul><ul><ul><li>test data generation </li></ul></ul><ul><ul><li>design improvement </li></ul></ul><ul><ul><li>code review & analysis </li></ul></ul><ul><ul><li>code improvement </li></ul></ul><ul><ul><li>test execution </li></ul></ul><ul><ul><li>result analysis </li></ul></ul><ul><ul><li>and more ... </li></ul></ul><ul><li>The result is the OOTWorks toolkit </li></ul>
  21. 21. Why OOTWorks <ul><li>It improves productivity and quality in </li></ul><ul><ul><li>Documentation </li></ul></ul><ul><ul><li>Design and code reviews </li></ul></ul><ul><ul><li>Testing, regression testing and maintenance </li></ul></ul><ul><ul><li>Test planning and scheduling </li></ul></ul><ul><li>It reduces the time and effort required to prepare for CMM/ audit each year </li></ul>
  22. 22. The OOTWorks Modules ORD (Object Relation Diagram) BBD (Block Bench Diagram) OSD (Object State Diagram) (Package Relation Diagram) PRD OID (Object Interaction Diagram)
  23. 23. Object Relation Diagram (ORD) <ul><li>Visualization of </li></ul><ul><ul><li>Classes, relationships, data members, function members, and source code, selectable by the user </li></ul></ul><ul><ul><li>Test order for unit and integration testing </li></ul></ul><ul><ul><li>Change impact and version comparison </li></ul></ul><ul><li>Computation of various OO metrics </li></ul><ul><li>Useful for </li></ul><ul><ul><li>program comprehension and assessment </li></ul></ul><ul><ul><li>documentation </li></ul></ul><ul><ul><li>design and code review </li></ul></ul><ul><ul><li>test scheduling and effort estimation </li></ul></ul>
  24. 24. An Object Relation Diagram
  25. 25. Object Relation Diagram (ORD) <ul><li>Generation of a cost-effective schedule </li></ul><ul><ul><li>for implementing the classes (required code skeleton) </li></ul></ul><ul><ul><li>for changing the classes </li></ul></ul><ul><ul><li>for code review of the classes </li></ul></ul><ul><ul><li>for testing the classes </li></ul></ul><ul><ul><li>it effectively reduces time, effort and costs to accomplish above tasks </li></ul></ul>
  26. 26. Generation of Cost-Effective Test Order Classes with test order 1:0 should be tested before classes with test order 2:0 to reduce the test effort.
  27. 27. Test Stubs Required for Randomly Selected Test Sequences
  28. 28. Saving from Test Order <ul><li>Average one person-hour is required to construct a test stub. </li></ul><ul><li>For the InterViews library, 191.88 person-hours, or close to 5 person-weeks are required. </li></ul><ul><li>Using test order, only one test stub is needed, the saving in effort and costs are tremendous even for this small program. </li></ul>
  29. 29. Generation of Test Schedule Critical path Testing of classes on the critical path must be completed on time to ensure that the test process will be completed on time.
  30. 30. Object Relation Diagram (ORD) <ul><li>Computation of various OO metrics </li></ul><ul><ul><li>Fan-in and fan out </li></ul></ul><ul><ul><li>Depth of inheritance tree </li></ul></ul><ul><ul><li>Number of lines of code </li></ul></ul><ul><ul><li>Length of invocation chain </li></ul></ul><ul><ul><li>Cyclomatic complexity </li></ul></ul><ul><ul><li>Number of children, etc. </li></ul></ul><ul><li>Useful for assessing program quality and spot potential problem areas </li></ul>
  31. 31. Various OO Metrics
  32. 32. Object Relation Diagram (ORD) <ul><li>Change impact analysis and visualization </li></ul><ul><ul><li>Compare change alternatives </li></ul></ul><ul><li>Version comparison and visualization </li></ul><ul><ul><li>Compare two versions/releases to identify changes and their impact </li></ul></ul><ul><ul><li>Visualizing the two versions/releases to facilitate code review and inspection to ensure that changes are made properly </li></ul></ul><ul><ul><li>Useful for maintenance, release review and regression testing to reduce time, effort and costs </li></ul></ul>
  33. 33. Change and Impact Analysis
  34. 34. Block Branch Diagram (BBD)
  35. 35. Block Branch Diagram (BBD) for test input preparation for test case preparation for test stub preparation
  36. 36. An Overly Complex Method Is Difficulty to Comprehend and Test
  37. 37. Block Branch Diagram <ul><li>Useful for white-box testing (basis path, data flow) </li></ul><ul><li>Useful for state transition construction </li></ul><ul><li>Useful for black-box testing </li></ul><ul><ul><li>Boundary value analysis </li></ul></ul><ul><ul><li>Functional testing </li></ul></ul><ul><ul><ul><li>Initialize parameters </li></ul></ul></ul><ul><ul><ul><li>Initialize input values </li></ul></ul></ul><ul><ul><ul><li>Identify and construct test stubs </li></ul></ul></ul><ul><ul><ul><li>Analysis of test results (changed variables) </li></ul></ul></ul><ul><li>Used for sequence diagram reverse engineering </li></ul>
  38. 38. Object State Diagram <ul><li>Hierarchical, concurrent, communicating state machines </li></ul><ul><li>Generated from C++/Java source code using a reverse engineering approach </li></ul><ul><li>Represents the dynamic state dependent behavior of objects </li></ul>
  39. 39. allowVend: unsigned 0,0 0,0 1,M 1,M CoinBox() CoinBox() Reset() Reset() Vend() AddQtr() [curQtrs > 0] AddQtr() AddQtr() ReturnQtrs() [allowVend !=0] Vend() S0 S1 S0 S1 curQtrs: unsigned An Object State Diagram for an incorrect coin box class
  40. 40. (S0, S0) (S0, S0) (S0, S0) (S0, S0) (S1, S1) (S1, S1) (S0, S1) (S1, S1) (S1, S0) Reset(), ReturnQtr() Reset(), ReturnQtr() ReturnQtr() AddQtr() AddQtr() AddQtr() Reset() (S0, S0) (S1, S0) ReturnQtr() Reset() AddQtr() Vend() Vend() Test tree showing the execution sequences of a COSD
  41. 41. off, off, off heat,off,off cool,off,off off, off, off SS, FR, AR SS.heat heat, on, off off, off, off off, on, off off, off, off cool, on, off heat, on, off off, on, off cool, on, on FR.turnOn SS.heat FR.turnOff AR.turnOn SS: Season Switch FR: Furnace Relay AR: A/C Relay Test tree showing a flaw in a thermostat system.
  42. 42. Sequence Diagram <ul><li>A sequence diagram describes the object interaction through time ordered message passing. </li></ul><ul><li>Elements and their Notations </li></ul><ul><ul><li>Objects </li></ul></ul><ul><ul><ul><li>Placed at top of the diagram across the horizontal axis </li></ul></ul></ul><ul><ul><li>Lifelines </li></ul></ul><ul><ul><ul><li>Dotted lines extending down the vertical axis </li></ul></ul></ul><ul><ul><li>Messages and Stimulus </li></ul></ul><ul><ul><ul><li>Horizontal solid labeled arrow. </li></ul></ul></ul><ul><ul><li>Focus of Control </li></ul></ul><ul><ul><ul><li>Tall thin rectangle along the vertical axis. </li></ul></ul></ul>
  43. 43. Sequence Diagram Example
  44. 44. Sequence Diagram Showing a Use Case
  45. 45. Usefulness of Sequence Diagram <ul><li>Understanding how use cases are implemented </li></ul><ul><li>Automatic generation of test cases and test data to test the implementation </li></ul><ul><li>Facilitating design and code review </li></ul><ul><li>Check if some behavioral design patterns are propertly implemented </li></ul>
  46. 46. Some Application Data <ul><li>OOTWorks can process millions of lines of source code and thousands of classes </li></ul><ul><li>Parsing of a 50,000 line C++ files finishes in 20 seconds </li></ul><ul><li>Platform independent (Windows, Linux, Unix,Soloaris, Mac, etc.) </li></ul><ul><li>Display and print very large ORD diagrams </li></ul><ul><li>Has been applied to real world applications with satisfactory results </li></ul>
  47. 47. Some Example Applications <ul><ul><li>Identification of isolated classes </li></ul></ul><ul><ul><li>Identification of possibly poorly designed OO software </li></ul></ul><ul><ul><ul><li>no use of inheritance and/or aggregation </li></ul></ul></ul><ul><ul><ul><li>only one parent class, all the other classes are direct children of the parent class </li></ul></ul></ul><ul><ul><ul><li>classes with several thousand lines of code </li></ul></ul></ul><ul><ul><ul><li>classes with very high fan-in and/or fan-out metrics </li></ul></ul></ul><ul><ul><ul><li>high cyclomatic complexity </li></ul></ul></ul><ul><ul><ul><li>classes having excessive number of methods may indicate poor cohesion (or too much responsibilities) </li></ul></ul></ul><ul><ul><ul><li>etc. </li></ul></ul></ul>
  48. 48. Possible Test Process ORD BBD selected class & method Functional Tests Generation Structural Tests Generation Tests Tests Execution Result Analysis Tester using variables used and changed using basis paths & symbolic execution interactive testing batch testing
  49. 49. Possible Test Process ORD OSD selected classes Method Sequence Tests Generation Fault Analysis Tests Tests Execution Result Analysis Tester analysis results
  50. 50. Summary Developer Tester SQA Project Manager <ul><li>time, effort and cost control </li></ul><ul><li>productivity and quality improvement </li></ul><ul><li>test scheduling </li></ul><ul><li>program understanding </li></ul><ul><li>documentation </li></ul><ul><li>verification </li></ul><ul><li>change impact analysis </li></ul><ul><li>metrics </li></ul><ul><li>test order </li></ul><ul><li>program understanding </li></ul><ul><li>test cases and test data preparation </li></ul><ul><li>regression test </li></ul><ul><li>metrics </li></ul>Maintenance <ul><li>version comparison </li></ul><ul><li>change impact analysis </li></ul><ul><li>regression test </li></ul><ul><li>verification </li></ul><ul><li>design and code review </li></ul><ul><li>metrics </li></ul><ul><li>documentation </li></ul>