Object Oriented Testing Strategy
Object Oriented Testing Strategy
Strategy
Objective
The objective of testing, stated simply, is to find the greatest possible number of
errors with a manageable amount of effort applied over a realistic time span.
unit testing focuses on the smallest compilable program unit—the subprogram (e.g.,
component, module, subroutine, procedure).
Once each of these units has been testing individually, it is integrated into a
program structure while a series of regression tests are run to uncover errors due to
interfacing the modules and side effects that are caused by the addition of new units.
Finally, the system as a whole is tested to ensure that errors in requirements are
uncovered.
Unit Testing in the OO Context
Rather than testing an individual module, the smallest testable unit is the
encapsulated class.
We can no longer test a single operation in isolation (the conventional view of unit
testing) but rather, as part of a class
Class testing for OO software is the equivalent of unit testing for conventional
software.Unlike unit testing of conventional software, which tends to focus on the
algorithmic detail of a module and the data that flows across the module interface,
class testing for OO software is driven by the operations encapsulated by the
class and the state behavior of the class.
Hierarchy testing
consider a class hierarchy in which an operation X() is defined for the superclass
and is inherited by a number of subclasses.
Each subclass uses operation X(), but it is applied within the context of the private
attributes and operations that have been defined for each subclass.
Because the context in which operation X() is used varies in subtle ways, it is
necessary to test operation X() in the context of each of the subclasses
Testing a single class as unit testing
class Product {
public: Product(string name, double price) : name(name), price(price) {}
string getName() const { return name; }
double getPrice() const { return price; }
private: string name; double price;
};
// Testing the independent class `Product`
int main()
{
Product p1("Laptop", 1200.50);
std::cout << "Product: " << p1.getName() << ", Price: $" << p1.getPrice() << std::endl; return 0;
}
Integration Testing in the OO Context
Thread-based testing, integrates the set of classes required to respond to one input or
event for the system. Each thread is integrated and tested individually. Regression testing
is applied to ensure that no side effects occur.
use-based testing, begins the construction of the system by testing those classes
(called independent classes) that use very few (if any) of server classes. After the
independent classes are tested, the next layer of classes, called dependent classes, that
use the independent classes are tested. This sequence of testing layers of dependent
classes continues until the entire system is constructed.
Cluster testing is one step in the integration testing of OO software. Here, a cluster of
collaborating classes (determined by examining the CRC and object relationship model)
is exercised by designing test cases that attempt to uncover errors in the collaborations
Examples
In thread-based testing for this "Place Order" process, we would simulate the sequence of steps
triggered by the user's action:
System Overview
● The breadth-first approach means testing transitions in a specific order. You start by testing
the simplest, initial transitions before moving on to new transitions that depend on the first
ones.
● For example, with a CreditCard class in the banking system:
○ Initial State: The credit card might start in an "undefined" state (e.g., no number
provided).
○ Transitions:
■ Defined: After reading the card number and expiration date.
■ Submitted: When the card is sent for authorization.
■ Approved: When authorization is received.
○ Breadth-First Testing: You would test each transition one by one, starting from
"undefined" to "defined," and only move to the next state (like "submitted") after
confirming the previous transition works correctly. This helps ensure each part of the
state sequence works properly before testing complex paths.