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

the single model program. Sometimes it is more convenient and flexible to keep<br />

the model programs separate and provide them as separate model arguments to ct.<br />

One common case is when one of the model programs represents the model of the<br />

expected behavior, whereas the other model programs are various scenarios.<br />

Probes. In some applications of model-based testing, it is useful to be able to check<br />

that some abstract view of the state of the IUT is consistent with the corresponding<br />

view of the model state. The actions that provide or check that view are sometimes<br />

called probes (or observers). The main property of a probe is that it does not change<br />

the state, that is, that the resulting state transition is a self-loop.<br />

Let us consider a concrete example using the bag model. First, we add a new<br />

feature called Probe to the bag model that contains a new action symbol CheckView.<br />

The purpose of a CheckView action is to serve as a probe. An action CheckView(v)<br />

that is enabled in a state s provides an abstract view of s by showing that the set<br />

of elements in the bag is v. The view is clearly an abstraction of the actual state<br />

because the multiplicity of the individual elements is omitted.<br />

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

{<br />

[Feature]<br />

static class Probe<br />

{<br />

static Set E()<br />

{ return new Set(Contract.content.Keys); }<br />

[Action]<br />

static void CheckView([Domain("E")]Set elems) { }<br />

static bool CheckViewEnabled(Set elems)<br />

{ return elems.Equals(Contract.content.Keys); }<br />

}<br />

}<br />

Test harness. When new actions, such as CheckView, are added to the model program,<br />

the test harness may need some adaptation. In this case the bag implementation<br />

stepper needs to be modified to deal with CheckView actions. This can be done as<br />

follows. An exception is thrown if the view of the model state is not consistent with<br />

the view of the implementation state. Note that the first (and only) argument of a<br />

CheckView action is a term that represents a set of strings. In order to convert that<br />

term into a value, the term is interpreted as a compound value that is then cast to a<br />

set of strings.<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!