Object state testing
Object state testing is a formal white-box software test design method testing object state behavior. State testing is complementary to local error detection of functional and structural testing. Interaction of class member functions are tested through object state transitions.[1] An object behavior is state based arranged due to method invocation sequence, which behavior is established due to parameter values and state, providing successor and return value. The ranges of values of a subset of member data of the object defines a state of an object. State transitions are deterministic finite due to the conditional execution of member functions. Object state tests can be determined from the source code (white-box) or from the specifications (black-box).
Requirements
- Initial state
- Parameter arguments
- Expected return value
- Expected object successor state
Defects
To ensure robustness, all void and valid method sequence invocation combinations need to be tested using state test cases[2]. Testing the object state brings out the following defects.
- Missing state transition
- Invalid transitions
- Wrong return value
- Invalid successor state
Object States
The behavior of a class object is definable and characterized by inhabited data member values. The run time execution path is determined by evaluating member and parameter values in decisions (conditions), affecting the class object behavior. Object states are segmented into independent domain member data interval combinations leading towards different execution paths.
State characterization
- Examine all path conditions of member functions for conditional literals
- For each conditional literal found, form domain intervals such that the conditional literal is evaluated to either True or False for all values in the interval.
Coverage
The amount of states and paths circumscribes test state coverage. Due to possible infinite cyclic path sequences, the path length needs limitation. The amount of methods is a minimum criterion of path length for permutations of method sequences . Instead of limiting method permutation sequences, an acyclic spanning tree addresses systematically path length including negative and positive path combinations through a state space.
Example
A soda machine requires two 50c coins for a soda. It provides five methods and three class member variables. The variable tmp holds temporary coins until a customer withdraws a soda[3]
#!/anaconda/bin/python
class SodaMachine:
total = 0
tmp = 0
withDraw = False
def __init__(self):
self.reset()
def add50c(self):
self.tmp = self.tmp + 1
if self.tmp > 1:
self.withDraw = True
def return50cs(self):
self.tmp = 0
def canWithDraw(self):
return self.withDraw
def draw(self):
if self.withDraw:
self.total = self.total + self.tmp
self.tmp = 0
self.withDraw = False
def reset(self):
self.total = 0
self.tmp = 0
self.withDraw = False
if __name__ == '__main__':
sodaM = SodaMachine()
sodaM.add50c()
sodaM.add50c()
sodaM.draw()
State Definition
The class contains the conditions:
add50c(): if self.tmp > 1
draw(): if self.withDraw
The two conditions are segmenting the class member variable values into four states :
| Member Interval | |||
|---|---|---|---|
| State | tmp | withDraw | validity |
False
|
✓ | ||
True
|
✓ | ||
True
|
✗ | ||
False
|
✗ | ||
State transition spanning tree
See also
- Multiple condition coverage
- Control flow graph
- Decision to decision path
- Elementary comparison testing
References
- ↑ Kung, D. C.; Suchak, N.; Gao and, J.; Hsia, P.; Toyoshima, Y.; Chen, C. (1994). "On Object State Testing". Proceedings of Computer Software and Applications Conference. IEEE Computer Society Press. pp. 222--227. Search this book on
- ↑ Tilo Linz (2014). Testing in Scrum, p. 51, Rocky Nook Inc., Santa Barbara. ISBN 978-1-937538-39-2 Search this book on
.
- ↑ https://github.com/jbloemendal/SodaMachine J. Bloemendal (2018), Test Case Design
This article "Object state testing" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Object state testing. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.

