A Practical Guide to Testing Object-Oriented Software

As an object interacts with other objects, it will receive multiple messages. These messages must be sequenced in accordance with the specification. Protocol testing investigates whether the implementation of a class satisfies its specification. The various protocols that an object participates in can be inferred from the pre- and postconditions for individual operations defined in its class. Identifying sequences of method invocations by combining a method whose postcondition enables the precondition of another method defines a protocol. It is much easier to see these sequences from the state diagram for a class than deriving them from written pre- and postconditions.

The interaction test suite includes tests of each protocol. This is basically a special form of life-cycle testing. Each protocol represents a life cycle for objects from the class under test in combination with instances of other classes. Each protocol corresponds to a sequence of states beginning with initial states of the two objects (as denoted on the state diagrams of the two classes), a sequence of states for each object, and ending with the terminal states (again, denoted on the state diagrams). A test case takes the two objects through one complete sequence of methods.

Consider the Timer class and its state diagram given in Figure 2.19. A protocol can be found by tracing through that state diagram. One protocol would be to create the object then sending one or more attach(...) messages followed by the enable() message, the disable() message, and finally, the delete() message. This provides a life-cycle test case. This provides an effective test of the object in the ways that it will interact with its client objects.

Категории