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.

Systems with Complex State 187<br />

<strong>We</strong> might want to consider only states where the counter is 0, 1, or2. Clearly,<br />

this is a small subset of the possible states for this model program, but it is a good<br />

place to start when trying to analyze the behavior of the system.<br />

To do this we can use a state filter. A state filter is a Boolean condition that must<br />

be satisfied in the end state of a transition in order for the transition to be included<br />

in the exploration. State filters say which states are “interesting” for analysis.<br />

<strong>We</strong> can keep the contract separate from the “small state” scenario limitation by<br />

putting the state filter in a feature:<br />

namespace Counter2<br />

{<br />

[Feature]<br />

static class SmallState<br />

{<br />

[StateFilter]<br />

static bool WithinCounterLimit()<br />

{ return Contract.counter < 3; }<br />

}<br />

}<br />

If you include the SmallState feature in your model program factory, then exploration<br />

via the mpv tool will include only transitions that result in a state in which<br />

the WithinCounterLimit method returns true.<br />

11.2.3 Strenghening enabling conditions<br />

Sometimes it is useful to omit certain kinds of transitions that are allowed by the<br />

contract model program but are of less interest for a test purpose or analysis goal.<br />

A general technique that can be used here is to strengthen enabling conditions.<br />

With this technique, you can add additional constraints that depend on the state of<br />

the system and the action parameters.<br />

namespace Counter2<br />

{<br />

static class PreconditionLimits<br />

{<br />

static bool IncrementEnabled()<br />

{ return Contract.counter < 2; }<br />

}<br />

}<br />

[Action]<br />

static void Increment() { }<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!