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.

186 Analyzing Systems with Complex State<br />

an understandable separation between scenario and contract model program. It also<br />

makes it possible for there to be several scenarios, not just one. Also, even though it<br />

is not explorable, the full contract model program is useful for other purposes, such<br />

as determining whether a trace taken from a log file is valid.<br />

11.2 Pruning techniques<br />

Once you have made your model program explorable by using the technique described<br />

in the previous section, you may still notice that it has an unbounded number<br />

of possible states. In this section we introduce some techniques for managing this<br />

proliferation of states.<br />

11.2.1 State and transition limits<br />

A simple way of limiting the number of transitions is to impose a limit and then<br />

halt exploration after the maximum number has been reached. You can do this by<br />

providing a maxTransitions command-line argument to the mpv tool.<br />

Although this technique is simple, it isn’t very systematic. Still, it is a useful stop<br />

gap when other pruning techniques haven’t been applied yet.<br />

11.2.2 State filters<br />

Sometimes it’s useful to consider only a subset of the possible states. For example,<br />

consider the following explorable, but infinite, model program:<br />

namespace Counter2<br />

{<br />

static class Contract<br />

{<br />

public static int counter = 0;<br />

}<br />

}<br />

[Action]<br />

static void Increment() { counter = counter + 1; }<br />

static bool DecrementEnabled() { return counter > 0; }<br />

[Action]<br />

static void Decrement() { counter = counter - 1; }<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!