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.

188 Analyzing Systems with Complex State<br />

Including this feature limits possible transitions by adding a state-based requirement<br />

to the Increment action. The effect of strengthening the precondition of Increment<br />

is the same as the state filter we described in the previous section.<br />

11.2.4 Scenarios and composition<br />

<strong>We</strong> showed how to use model program composition as a means of scenario control in<br />

Section 7.3. This technique works well for models that have complex state because<br />

it is a very general way to control exploration that can finitize parameter domains<br />

and strengthen preconditions.<br />

For example, we could make the infinitely branching Counter model program<br />

shown in Section 11.1 explorable using composition. To do this, we would create a<br />

finite state machine with only one state and five self-looping transitions.<br />

FSM(0, AcceptingStates(0),<br />

Transitions(t(0, ModularIncrement(0), 0),<br />

t(0, ModularIncrement(1), 0),<br />

t(0, ModularIncrement(2), 0),<br />

t(0, ModularIncrement(3), 0),<br />

t(0, ModularIncrement(4), 0)))<br />

If we compose this FSM with the Counter model program using the technique<br />

described in Section 7.3.2, the result is a model program that is explorable. To do<br />

this, we could put the FSM into a text file CounterArgs.txt and include it as an<br />

argument to the mpv tool:<br />

mpv /r:Counter.dll Counter.Factory.Create /fsm:CounterArgs.txt<br />

Note that the FSM in this example had only one state. Its effect was the same as<br />

the Domain attribute shown in Section 11.1.<br />

In general, it is possible to consider scenarios provided by arbitrary model programs.<br />

For example, we could consider the scenario where the modular counter is<br />

incremented by even numbers and odd numbers in alternation.<br />

FSM(0, AcceptingStates(0),<br />

Transitions(t(0, ModularIncrement(0), 1),<br />

t(1, ModularIncrement(1), 0),<br />

t(0, ModularIncrement(2), 1),<br />

t(1, ModularIncrement(3), 0),<br />

t(0, ModularIncrement(4), 1)))<br />

This is a contrived example, just for the purposes of demonstrating the idea.<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!