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 189<br />

11.2.5 State grouping<br />

State grouping is a pruning technique that limits exploration to unique representatives<br />

of user-provided state properties. If during exploration a state is encountered<br />

that does not produce a new value of one of the desired properties, it is pruned away.<br />

In other words, state exploration with grouping seeks to produce distinct examples<br />

of the abstracted state values, rather than distinct states. This can reduce the number<br />

of states greatly while still uncovering “interesting” traces.<br />

An attribute in the form [StateProperty("name")] can be placed on a method,<br />

property or field to define a state property named name. The value of the property in<br />

a given state is the return value of the method, or the value of the field or property in<br />

that state. State properties are sometimes called abstraction functions because they<br />

remove detail.<br />

Here is an example.<br />

namespace Stack<br />

{<br />

static class Contract<br />

{<br />

static Sequence contents = Sequence.EmptySequence;<br />

}<br />

}<br />

static readonly Set elements = new Set(0,1,2,3,4,5);<br />

[Action]<br />

static void Push([Domain("elements")] int x)<br />

{ contents = contents.AddFirst(x); }<br />

static void PopEnabled() { return !contents.IsEmpty; }<br />

[Action]<br />

static void Pop() { contents = contents.Tail; }<br />

[StateFilter]<br />

static bool SizeLimit() { return contents.Count < 6; }<br />

[StateProperty("Count")]<br />

static int Count() { return contents.Count; }<br />

If we explore this model program using the mpv tool without state grouping, we<br />

notice that it branches quickly. However, if we use the Count property as a state<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!