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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

262 Reactive Systems<br />

namespace Bag<strong>Model</strong><br />

{<br />

[Feature]<br />

static class Draw<br />

{<br />

static Bag B { get { return Contract.content; } }<br />

static bool drawing = false;<br />

[Action]<br />

static void Draw_Start() { drawing = true; }<br />

static bool Draw_StartEnabled() { return !drawing && !B.IsEmpty; }<br />

[Action]<br />

static void Draw_Finish([Domain("B")]string e)<br />

{ drawing = false; Contract.content = B.Remove(e); }<br />

static bool Draw_FinishEnabled(string e)<br />

{ return drawing && B.Contains(e); }<br />

[Action("Add"), Action("Delete")]<br />

[Action("Lookup_Start"), Action("Lookup_Finish")]<br />

[Action("Count_Start"), Action("Count_Finish")]<br />

static void Other() { }<br />

static bool OtherEnabled() { return !drawing; }<br />

}<br />

}<br />

Figure 16.2. A dependent Draw feature for Bag<strong>Model</strong> in Figure 12.2.<br />

stepping. In other words, queueing of obsevable actions is not needed. In this case,<br />

nondeterminism is resolved immediately when it occurs. Synchronous stepping, as<br />

discussed in Section 12.2.3, is then an adequate solution to harness the IUT for<br />

testing.<br />

Shallow nondeterminism. In some cases, nondeterminism arises only because of<br />

multiple possible outputs to some inputs. In particular, all states of the model program<br />

are such that either all enabled actions in a state are controllable or all enabled actions<br />

in a state are observable. Say a state is active in the first case and passive in the<br />

second case. Moreover, a transition from a passive state leads to an active state.<br />

To illustrate this case on a concrete example, recall the bag example from Chapter<br />

12. Suppose that a dependent feature called Draw is added to the bag model<br />

program that allows elements to be chosen and removed (drawn) from the bag (see<br />

Figure 16.2).<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!