Testing of Object Oriented Systems
Testing of Object Oriented Systems
Systems
Differences in OO Testing
OO Language is Data or Object Centric. There is
no
separation between data & the methods that
operate on the data.
• Testing in OO systems should tightly integrate
data & algorithms.
• Testing in OO system covers following topics.
– Unit Testing a class
– Putting classes to work together (Integration
testing of classes)
– System testing
– Regression testing
– Tools for testing OO system
Procedural Programming
Procedure Oriented Software
The Procedure Oriented languages are
‘algorithm centric’.
They are characterized by
◦ Algorithms + Data Structures=Programs.
Object Oriented Software
The Object Oriented languages are ‘Object centric’.
Algorithm & Data are tightly coupled.
Data & the methods operating on the data go
together as individual unit.
Classes form the fundamental building blocks of OO
systems.
Definition: Class : It is a representation of a real life
object.
It provides a template that indicates the attributes &
methods of an object.
Definition : Object: It is a real life entity made up of
attributes or variables & methods that operate on the
variables.
All methods & properties of a class apply to all the
objects
MESSAGE PASSING
Objects communicate with each
other by sending & receiving
information.
A message for an object is a request
for execution of a procedure.
Message Passing involves specifying
the name of object, the name of the
function (msg.) & the information to
be sent.
Syntax : object . msg (info)
Object is an instance of a class.
Message passing: Objects communicate with
each other by sending & receiving information.
Message Passing involves specifying the name
of object, the name of the method (msg.) & the
information to be sent.
Syntax : object . msg (info)
DATA ABSTRACTION:
It refers to the act of representing
essential features without including
the background details.
The way the programs are written & tested
in OOP changes due to
◦ The paradigm shift from algorithm centric,
control based approach to Object-centric,
Message-based approach
◦ Messages passed to the objects that are not
instantiated, results in run-time errors. Such
errors are difficult to catch by the Static Method.
◦ Each class may have a set of errors that are
raised as error conditions.
◦ Transfer of code to these exceptions causes
break in the Program Sequence flow, which
needs to be tested.
◦ Nested classes may have nested exceptions.
Object’s interaction between the multiple levels
of testing should be proper and is difficult to
test.
Testing of OO Systems
Itbroadly covers the following
topics
1. Unit Testing a Class
2. Putting classes to work together
(Integration Testing of Classes)
3. System Testing
4. Regression Testing
5. Tools for testing OO system
Unit Testing a Set of Classes
Classes are the building blocks of the entire
OO systems.
They need to be unit tested before being put
together.
Need for testing the classes:
1. A class is intended for heavy reuse. Defects in a
class affects every reuse.
2. Many defects get introduced at the time of class
definition.
3. A class may have different features
4. Synchronization of data & methods should be unit
tested at the class level
5. Since OOP supports reuse through Inheritance,
building blocks should be thoroughly tested.
Conventional methods that apply to testing
the classes
Boundary Value analysis & Equivalence
Partitioning can be used to effectively test
data members.
Function Coverage: Ensures that every
method(function) is tested.
Condition Coverage, Branch Coverage,
Code complexity etc WBT techniques are
used to test the procedural logic of
methods.
Stress Testing can be performed to test
stress related problems due to multiple
instantiations of class by multiple clients.
Conventional methods that apply to testing
the classes
State Based Testing of BBT is the most
appropriate.
Special Considerations for testing the classes
To test the instantiated objects, messages
have to be passed to various methods.
To decide the sequence of message
passing, Alpha-Omega method is used.
Principles of Alpha-Omega method
1. Test the objects through their life cycle i.e.
From instantiation to destruction.
2. Test the simple methods first & then the
complex methods.
3. Test the methods from private through public.
4. Send a message to every method at least
once.
Alpha-Omega method has following steps
1. Test the constructors first. In case of multiple
constructors, test all.
2. Test the get methods or accessory methods-
Ensure variables in the class are accessed by
appropriate methods
3. Test the methods that modify object
variables. Test sequential, branching &
looping constructs for proper execution.
4. Test destruction of objects :
1. Call of destructors,
2. Releasing resources,
3. Ensure that no further accidental access is possible
Incremental Testing
Inheritance makes Testing Complicated
Following things are required to be tested :
1. Changes made to the base Class variables &
methods
2. New variables & methods in the derived class
Even the unchanged variables & methods needs
to be retested. The testing is decided as follows
3. Whenever an unmodified variable is referenced
in a new or modified method
4. Whenever an unmodified method is called in a
new or modified method.
Incremental Class Testing
It is a method of testing all the changes
or new additions thoroughly at the point
of creation and selective re-testing of
other unchanged attributes.
This solves
◦ the problem of exhaustive Testing
◦ Overcoming Risk
1. Multiple inheritance makes testing
challenging.
2. Interfaces or virtual class serve good
starting point for testing.
Putting Classes to work together – Integration
Testing
OO systems are not a collection of discrete objs or
classes
Objs or classes should co-exist, integrate and
communicate with one another.
Hence testing that classes work together i.e. Integration
Testing is imp
Differs from procedure oriented approach
Can not use only method names to check sequence as
multiple methods have same defn but diffn
functionalities.
Need to be tested according to the context.
Challenges - Polymorphism
Dynamic binding