TESTING OF OBJECT ORIENTED SYSTEMS Algorithms Data structuresProgram
TESTING OF OBJECT ORIENTED SYSTEMS
�Algorithms +Data structures=Program �Class �Object �Constructor �Encapsulation �Inheritance �Polymorphism �Dynamic binding
Differences in OO Testing �Testing an OO system should tightly integrate data & algorithm �It includes foll. : 1. Unit testing a class 2. Putting classes to work together (integration testing) 3. System testing 4. Regression testing 5. Tools for testing OO systems
Unit testing a set of classes �Classes are building blocks for an entire OO system �Classes have to be unit tested �Why classes have to be tested first? 1. Class is intended for reuse. Defect in a class can affect every instance of reuse 2. Many defects are introduced at the time of class definition. Delay in catching these defects make them go into client classes. Thus fix for the defect would have to be reflected in multiple places, resulting in inconsistencies 3. Class is a combination of data & methods. If data & methods do not work properly at unit test level, it may cause defects in later classes 4. Unless building blocks are thoroughly tested stand alone, defect arising out of these contexts may be noticed many times later.
Conventional methods that apply to testing classes �Every class has certain variables. Techniques like boundary value analysis & equivalence partioning can be used �Not all methods are exercised by all the clients. The methods of function coverage can be used to ensure that every method is exercised �Every class will have methods that have procedural logic. The techniques of condition coverage, branch coverage, code complexity can be used �Since a class is instantiated multiple times by different clients, techniques of stress testing can be used
�Object goes through different states. �The messages that are passed to class act as inputs to trigger the state transition �Some criteria that can be used for testing are: �Is every state reached at least once? �Is every message generated & tested? �Is every state transition achieved at least once? �Are illegal state transition tested?
Special considerations for testing classes �In order to test objects, messages have to be passed to various methods. �In what sequence does one pass messages to objects? �One of the method is “Alpha-Omega method” �This method works on foll. Principles: 1. Test the object through its life cycle from birth to death ( instantiation to destruction). Object is instantiated through constructor method; then variables are set to a value. During execution, the values may get modified. Object is destroyed by destructor method
2. Test the simple methods first & then the more complex methods. The more complex methods will build upon simpler methods 3. Test the methods from private through public methods. Private methods are methods that are not visible outside the class 4. Send a message to every method at least once. This ensures that every method is tested at least once �Steps of Alpha-Omega method: 1. Test the constructor methods first. When there are multiple constructors, all constructor methods should be tested individually
2. Test the get or accessor methods. Accessor methods are those methods that retrieve the values of variables in an object for use by calling programs. This ensures that variables in the class definition are accessible by appropriate methods 3. Test the methods that modify the object variables. These are the contents of variables, methods that set the content of variable, methods that loop through various variables 4. Finally object has to be destroyed & when object is destroyed, no further accidental access should be possible. Resources used by object should be released.
�Encapsulation is meant to hide the details of class from the clients of the class �The inside behavior of encapsulated part is less visible to the tester �White box testing of classes with encapsulation becomes difficult �A class can: ü Inherit variables & methods from its parent class ü Redefine variables & methods from its parent class ü Define new variables & methods that are specific to it & not applicable to parent ü When a class is introduced for the first time, all variables & methods have to be tested fully. From then on whenever a class is derived from a parent class, the foll. Things need to be tested: -
ü The changes made to the base class variables & methods & attributes ü New variables & methods that have been introduced in derived class �Testing all changes or new additions thoroughly a point of creation & selective re-testing of other unchanged attributes is called incremental class testing �Two other forms of inheritance are: �Multiple inheritance: child class is derived from two parent classes �Abstract class (virtual method)
Putting classes to work together (integration testing) �An OO system is not only collection of discrete objects or classes but these objects or classes should co-exist , integrate & communicate with each other �OO systems are designed to be made up of number of smaller components that are meant to be reused, testing these classes work together is important �In POP system, testing is done by giving different data to exercise the control flow path. The control flow path is determined by the functions called by the program, from start to finish.
�In OO system , the way in which various classes communicate with each other is through message �Message format is: �<instance name>. <method name>. <variable> �Methods with same name perform different functions �The property by which meaning of a function or operator varies & same operation behaves differently in different context is called polymorphism �In what order classes should be tested? �Various methods of integration like top-down, bottom -up, big-bang etc. can be used
�OO systems are built out of reusable components. Hence integration testing will be critical �There is more parallelism in development of components of OO systems, so need for integration testing is higher �Sequence of availability of classes have to be considered while performing integration testing
System testing & interoperability testing �OO systems are designed using smaller reusable components �A class may have different parts, not all of which are used at the same time. When different clients start using a class, they may be using different parts of a class & these may introduce defects at system testing phase �Different classes may be combined together by a client & these combination may lead to new defects �An instantiated object may not free all its allocated resources thus causing memory leaks which will come up in system testing phase
Regression Testing of OO System �As a result of heavy reliance of OO systems on reusable components, changes to one component could have unintended side effects on clients that use the component �Also because of cascaded effects of changes resulting from properties like inheritance frequent integration & regression testing is necessary
Tools for testing of OO systems �Use cases �Class diagrams �Sequence diagrams �State charts
Use cases �It represents various tasks that a user will perform when interacting with the system �Use cases go into details of specific steps that user will go through in accomplishing each task & system response for each step
Class diagrams �It represents the different entities & different relationships that exist among the entities �Class diagram build upon classes of a system �It has foll. elements/: �Boxes: rectangular box represents class. �Association: it is a relationship between 2 classes by a line. It can be 1 -1, 1 -many, many-1 etc. �Generalization: it represents child classes that are derived from parent class
�It is useful to due foll. Reasons: �It identifies elements of the class & enables identification of boundary value analysis, equivalence partitioning �The association help in identifying tests for referential integrity constraints �Generalization helps in identifying class hierarchies & thus help in planning incremental class testing as & new variables & methods are introduced in child classes
Sequence diagrams �OO systems works by communicating messages across the various objects. �Sequence diagram represents a sequence of messages passed among objects to accomplish a given application scenario �The objects that participate in a use case are listed horizontally. �The lifetime of an object is represented by vertical line from top to bottom. �A dashed line on top represents object construction/activation, while X in the end indicates destruction of object
�The messages are represented by horizontal lines between 2 objects �There are different types of messages. They can be blocking & non-blocking �Some messages are passed conditionally ex. IF statement �Sequence diagram helps in testing by: ü Identifying end-to-end messages ü Tracing intermediate points in end-to-end transaction ü Providing for several typical message calling sequence
Activity diagram �It depicts the sequence of activities that takes place �It is used for modeling typical work flow in an application & brings out the elements of interaction between manual & automated processes. �The entire work flow is visualized as a set of actions states, each action state representing an intermediate state of result �Sequence diagram helps in testing by: ü The ability to derive various paths through execution. It can be used to arrive at the code complexity & independent paths through program code ü Ability to identify the possible message flows between an activity & an object, thereby making message based testing effective
State based �When an object can be modeled as a state machine, then the techniques of state based testing can be applied directly
- Slides: 29