Non-Linear Test Sheets

This example is similar to the second example from Basic Test Sheets except that the method invocation rows do not have to be executed in the order they are defined and may even be executed multiple times.

(click to enlarge)

Similar to the invocation line (double line separating input parameters and expected return values) there is a double line below the last method invocation row. Below this line the behavior specification starts. Each row of the behavior specification represents a state of a state machine. The state machine starts in the first state that is being specified right below the double line and stops execution once a state is reached without any valid transitions.

Each column in a row specifies a transition. A transition consists of a guard, executed invocations and a subsequent state. The starting state has only one transition with no guard, the intermediate state has three possible transitions each with a guard and the terminating state does not have any transitions at all.

The transition in the starting state specifies that rows 3 and 4 are executed and the state machine then changes to the state specified in row 8.

The intermediate state repeatedly pushes new elements onto the stack while staying in the same state (first transition). If the stack is already half full (#n in a guard stands for how many times row n has been executed) not only is a new element pushed onto the stack but it is also checked whether the current top element really is the newly pushed element (second transition). The last transition is peformed when the stack is full. This transition executed rows 5 and 6 and then changes the state machine to the terminating state. It checks whether the current top element is the last element that was pushed onto the stack and if taking one element from the stack results in said element.