State Based Testing
State based testing is a black-box unit testing
technique for identifying test cases that identify defects
involving the implementation of the state models of classes
with logical state.
The behavior of objects can be a function of their logical
state. The same test stimuli (e.g., message with parameters or
exception with attributes) can produce different test results
depending on the state of the object under test and the states
of its collaborators, thereby increasing the difficulty of
regression testing. For example, pushing an item onto a bounded
stack behaves differently depending on whether or not the stack
is full.
Merely testing every state or testing every transition
(i.e., operation) is inadequate; one must test every operation
in every state.
State based testing is very popular in the object community
and has long been used in the hardware world. It also has a
strong theoretical foundation.
The typical objectives of state based testing are to:
- Ensure adequate testing.
- Determine if the class properly implements its state
model.
- Cause failures due to state defects.
State based testing can typically begin when the following
preconditions hold:
- The tester(s) has been trained in state based
testing.
- The state model of the item under test (software
component or class) exists.
- The interface and responsibilities of the item under test
have been defined.
State based testing is typically complete if the following
postconditions hold:
- Every software component and class with logical states
has been tested.
- The test cases caused the corresponding objects under
test to make every transition from every state.
During state based testing, the unit testers typically
perform the following steps:
- Create a state transition diagram for each relevant class
with logical states.
- Transform the state transition diagrams into a transition
trees, whereby the root of the tree is the start state, and
each branch is made up of a series of transitions between
states that terminates when a transition returns the object
under test to a previous state.
- Create a state-based test suite for the class under test,
whereby each test case corresponds to a branch of the
transition tree. Each test case starts by instantiating an
object under test in the start state. The test case then
sends the object under test a series of test stimuli (either
messages with appropriate parameters or exceptions with
appropriate attributes) that are intended to walk the object
under test down the corresponding branch of the transition
tree.
- The test oracle is the state transition diagram. Each
test case compares each actual post-stimuli state of the
object under test with the state that is predicted by the
branch of the transition tree that generated the test
case.
State based testing typically results in the following work
products:
- Test suites containing test cases that cause each
software component or class with logical state to make every
transition from every state.
State based testing is subject to the following
limitations:
- State based testing requires correct state models of all
relevant classes (i.e., the class under test, its
collaborators, any input parameters, any values) in order to
develop the test cases.
- State based testing requires complete state models (i.e.,
state models of flattened classes). It is not adequate to use
the partial state model of a class without including
inheritance.
Guidelines
- Do not merely create one test case per:
- Combine equivalence set and state based testing to
minimize the number of test cases to develop and
maintain.