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.

Systems with Complex State 185<br />

relation does the modified model program have to the original? Mixing parameter<br />

restrictions inline with our model confuses the contract (the system’s specified<br />

behavior) with a scenario (a particular situation of interest for analysis or testing).<br />

A better way to deal with this case would be to use the Feature attribute we saw<br />

in Section 7.2. To do this, we create a new class within the same namespace:<br />

namespace Counter<br />

{<br />

[Feature]<br />

static class SmallDomain<br />

{<br />

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

}<br />

}<br />

[Action]<br />

static void ModularIncrement([Domain("inputs")] int x) { }<br />

<strong>We</strong> can combine the SmallDomain feature with the contract model program by means<br />

of a factory method. Factory methods were introduced in Section 6.2.1.<br />

namespace Counter<br />

{<br />

public static class Factory<br />

{<br />

public static <strong>Model</strong>Program Create()<br />

{<br />

return new Library<strong>Model</strong>Program(typeof(Factory).Assembly,<br />

"Counter", Set.EmptySet);<br />

}<br />

}<br />

}<br />

public static <strong>Model</strong>Program CreateFinite()<br />

{<br />

return new Library<strong>Model</strong>Program(typeof(Factory).Assembly,<br />

"Counter", new Set("SmallDomain"));<br />

}<br />

The factory contains methods that create either of two versions of the Counter<br />

model. The model program produced by CreateFinite includes the feature that<br />

restricts the domain to five elements. The advantage of this approach is that it keeps<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!