Assertions can be used to check adherence to pre- and postconditions of method calls. It is desirable, that assertions can be turned on and off selectively. Monitoring of parameters, return values, and exceptions helps to understand the software system and to localize faults. Direct manipulation of instance variables is sometimes necessary to test the effect of method calls for particular object states. Breaking the encapsulation might be disadvantageous if, for example, object states are set and tested that are not relevant to real system execution.
Classes often have significant state-dependent behavior.
State-based testing is therefore important. In the best case, state machines are described in a CASE tool. If not it desirable that the state machine can be derived from the source code. At least, it should be possible to model the state machine within the test tool. The postconditions of methods define the target state of method calls.