OO Testing
OO Testing
● Although…
● Object-oriented analysis and design can lead to a better system
architecture, and
● Object-oriented programming enforces a disciplined coding style
● In other words…
When can we trust the reports of an untested object about its state?
● Encapsulation
● Inheritance
Relationship between classes that allows the definition
of a new (derived) class based on the definition of an existing (base) class.
The derived class can then be refined by modifying or removing the inherited
operations, or by adding new properties.
● Single inheritance
● Properties are inherited from a single class
• Strict: the derived class can only be refined by adding new properties
• Subtyping: besides the properties of strict refinement, it allows the redefinition
(overriding) of the inherited properties
● Multiple inheritance
● Properties are inherited from multiple (many) classes
Impact of OO on Testing
● Inheritance
● Allows reuse of both specification and implementation
● Shares features present in classes previously defined
● The preexisting classes do not have to be modified or made
aware of the new class
Impact of OO on Testing
When can we assume that the superclass has already been tested?
● So...
● A method which has been tested in a superclass needs a retesting when it
is reused by a subclass
● Even if a method is inherited from a superclass without any modification
(strict inheritance), it has to be retested in the subclass context
Impact of OO on Testing
● Polymorphism
● Other issues…
● Concurrency
● Correct behavior of concurrently executing objects
● Sequences of messages
● The packaging of methods in a class is fundamental to OO
● Messages have to be executed in some sequence
● Unit Testing
What is a unit?
A method? A class? A group of classes?
● Unit Testing
● Intra-Method Testing
● Tests a specific method of a class
● Inter-Method Testing
● Methods of the same class may interact to implement a given functionality
• Kind of integration that should be tested
● Intra-Class Testing
● Tests public method interactions through different sequences of calls to
such methods
● Identifies possible sequences that lead the object to an invalid state
• Since the user may invoke the public method in many different orders, the
intra-class testing gives one the confidence that different sequences of calls act
correctly
OO Testing Phases: Integration
● Integration Testing
● Integration of classes to create the application system
● Closely tied to the overall development approach
● Inter-Class Testing
● Test public methods: not only those in a single class, but also those in
different classes
• For each client class, use the list of class operators to generate a series of
random test sequences. The operators will send messages to other server
classes.
• For each message that is generated, determine the collaborator class and the
corresponding operator in the server object.
• For each operator in the server object (that has been invoked by messages sent
from the client object) determine the messages that it transmits.
• For each of the messages, determine the next level of operators that are invoked
and incorporate these into the test sequence.
OO Testing Phases: System
● System Testing
● Considers the OO software as a “whole”
● Looks for the errors in the whole system, including operating
system call errors, performance errors, partition errors...
● Alpha and beta testing can also be used as a complement
● Generally based on black box criteria
● No fundamental difference from procedural and OO software
Procedural vs. Object-Oriented Testing
Testing Phases
Procedure or Class
Subroutine (Methods)
Integration Testing
System Testing
Entire Entire
System System
Procedural vs. Object-Oriented Testing
● Base Class
● Testing base classes is similar to unit testing of modules in
traditional systems
● Goal: ensure the base classes work correctly in isolation, before
their integration
● Manually prepare a “thorough” test suite
● Apply it to each base class
● Keep information on the designed test cases
● SUnit Framework
● Test Plan
Testing OO Systems
● Testing a subclass
● Test the subclass class in conjunction with its parent
● Determine test cases required for the subclass
• Incrementally update the parent class history (methods tested, test
suite applied, test status) to reflect differences from the parent class
• Test new attributes or those inherited, affected attributes
– Also test their interactions
● Testing a subclass
● New or untested feature in the subclass
● Develop new complete test suite for it
● Prepare intra- and inter-class tests
• Test a new data member by testing the class methods with which it
interacts
● Inherited Features
● Very limited retesting of classes is required
● Integration testing is required if class either:
• Interacts with new or redefined variable; or
• Accesses the same instances in the class’s representation as other
methods
Testing OO Systems
● Testing a subclass
● Redefined Features
● May be able to reuse black box test cases
• Functionality unchanged
● New white box tests will be required
• Implementation sure to change
General Test Case Design Issues
● What design models are useful for reasoning about probable sources of error?
● What techniques may be used to construct test cases from models, specifications and
implementations?
● How much testing is sufficient for methods, classes, application systems and components of
reusable libraries?
● To what extent should inherited features be retested? Under what conditions must features
inherited from a superclass be retested in a subclass?
● What models for understanding collaboration patterns are useful for testing?
● How can models of the state of an object, class or system under test be used?
● How can state-dependent behavior be verified when state control is often distributed over an
entire object-oriented application?
● How can clients and servers linked by dynamic binding (polymorphism) be tested?
● How can regression tests be formulated and conducted to ensure the integrity of modified
classes?
Specific OO Test Techniques
● Combinatorial Methods
● Decision Tables
● Decision Trees
● State Machines
● Events, Transitions, Guards
● Activities, Actions
● UML-Based Model
● Association Tests
● Use Case Tests, Interaction Tests
● Responsibility-Based
● Traditional
● Boundary, Control Flow, Partitions
● Controlled Exception Testing (exceptions/handlers)
● Frequency Allocation
Comments on Testing Interfaces
● Testing methods:
● Work through your scenarios
● Check functionality explicitly mentioned in the spec
Robustness of an Interface
● Testing method:
● Developers tend to avoid doing things they know will break the
system, so it’s harder to test this yourself
● Give your interface to 2-3 of your friends and ask them to play
with it
● CS majors are really good at breaking things!
• Profs are even better
● Some actions do “void the warranty”
Usability of an Interface
● Test methods:
● Give your system to 2-3 people who haven’t seen it
before and ask them to accomplish a particular task
● Can’t reuse people for this!
● Aim for people in your user group
● Watch what they do and listen to them
Next on the Menu
● Midterm!
● Questions?