27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

202 <strong>Testing</strong> Systems with Complex State<br />

• The IsInAcceptingState property returns true if the current model state is an<br />

accepting state. A test run is allowed to finish only in an accepting state.<br />

• The Reset action restores the model to its initial state. After reset CurrentState<br />

is the initial state of the model. This does not mean that the full tester state is<br />

restored to the initial state. Typically, the strategy keeps history of prior test runs<br />

that affects what action is selected next.<br />

• The IsActionEnabled method returns true if the given action is enabled in the<br />

current model state. It returns false otherwise, and outputs a reason why the<br />

action is not enabled.<br />

• The SelectAction method returns an action that is enabled in the current model<br />

state and whose action symbol is in the given set of action symbols. The given<br />

set of action symbols may be a proper subset of ActionSymbols. The method<br />

returns null if no action can be selected.<br />

• The DoAction method executes the given action in the model so that CurrentState<br />

gets the target state of this transition. A precondition of this method is that the<br />

given action is enabled in the current state. If the action is not enabled, the<br />

behavior of the model program is unpredictable.<br />

The strategy is constructed for a given model program and holds a reference to it.<br />

The strategy stores the current state of the model and it knows, by using the model<br />

program, which actions are currently enabled, that is, which actions are enabled in<br />

the current state. The strategy can use additional state to record history, for example,<br />

previously taken actions, in order to implement a particular algorithm for selecting<br />

the next action to be executed.<br />

12.3.1 Default strategy<br />

A default or basic strategy for a given model program is provided by the Strategy<br />

class. The basic strategy has no additional tester state, it implements a so-called<br />

memoryless action selection strategy; a call to SelectAction computes, in the current<br />

state, the set of all enabled actions with the given action symbols and returns a<br />

randomly chosen action from among those, or null if the set is empty.<br />

<strong>We</strong> can use the conformance tester ct to run the restricted bag model program<br />

against the bag stepper. As it happens, the very first test fails with a trace consisting<br />

of a single action Lookup Start(null) with a failure reason that null cannot be a<br />

key in the dictionary that is used to implement the bag. <strong>We</strong> can fix that bug easily<br />

by counting null values separately and not trying to insert null or to look it up in<br />

the dictionary. For now let us assume that the set of parameters is restricted to ""<br />

and "b"; that is, we change the definition of E in Figure 12.3 to<br />

readonly static Set E = new Set("","b");<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!