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]
OO conceptualization, design and programming significantly impact the quality
many developers’ mindset is still in procedural design and programming
anti-design patterns are commonly found in OO design and OO code
Case Study 1: Analysis of a Fedex Ship Manager Software
This software was designed and implemented by a team of students taking an OO software engineering class
It has nothing to do with Fedex
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
This program is working but it has some design problems
We show how OOTWorks can be used to detect these design problems
Poor Conceptualization NextAfternoon, OvernightExpress, Ground, etc. are services. They are not a RateChart. It is better to use association.
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.
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.
Better Design Better conceptualization. The services use ZoneChart and Delivery Area Surcharge to calculate rates.
Better Design The subclasses inherit and use all of the methods of the superclass.
Automatic Design Improvement The repeated code can be deleted from the subclasses.
Hierarchical, concurrent, communicating state machines
Generated from C++/Java source code using a reverse engineering approach
Represents the dynamic state dependent behavior of objects
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
(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
off, off, off heat,off,off cool,off,off off, off, off SS, FR, AR SS.heat SS.cool heat, on, off off, off, off off, on, off off, off, off cool, on, off heat, on, off off, on, off cool, on, on SS.off FR.turnOn SS.off SS.off SS.heat SS.cool FR.turnOff SS.off AR.turnOn SS: Season Switch FR: Furnace Relay AR: A/C Relay Test tree showing a flaw in a thermostat system.
Identification of possibly poorly designed OO software
no use of inheritance and/or aggregation
only one parent class, all the other classes are direct children of the parent class
classes with several thousand lines of code
classes with very high fan-in and/or fan-out metrics
high cyclomatic complexity
classes having excessive number of methods may indicate poor cohesion (or too much responsibilities)
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
Possible Test Process ORD OSD selected classes Method Sequence Tests Generation Fault Analysis Tests Tests Execution Result Analysis Tester analysis results