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.

212 <strong>Testing</strong> Systems with Complex State<br />

switch (a.FunctionSymbol.Name)<br />

{<br />

case ("CheckView") :<br />

Set modelView =<br />

(Set)CompoundValue.InterpretTerm(a.Arguments[0]);<br />

Set implView = new Set(bag.table.Keys);<br />

if (!modelView.Equals(implView))<br />

throw new Exception("Inconsistent views of state: model:" +<br />

modelView + " iut:" + implView);<br />

return null;<br />

case ...<br />

}<br />

Scenarios. Probes are usually checked more frequently than other actions. For<br />

the bag model, we can express this using an FSM scenario called ProbeScenario.<br />

It requires that each Add action and each Delete action must be followed by a<br />

CheckView action. In the same scenario we also disable all lookup and count actions.<br />

FSM(0,AcceptingStates(0),<br />

Transitions(t(0,Add(),1),t(0,Delete(),1),t(1,CheckView(),0)),<br />

Vocabulary("Lookup_Start","Count_Start"))<br />

The following additional FSM scenario called AddDeleteScenario requires that<br />

all Add actions happen before all Delete actions:<br />

FSM(0,AcceptingStates(0,1),<br />

Transitions(t(0,Add(),0),t(0,Delete(),1),t(1,Delete(),1)))<br />

In general, it may be useful to have a whole collection of FSM scenarios stored<br />

in separate files and experiment with various combinations of them using the fsm<br />

option of ct, without having to create factory methods for all of the combinations.<br />

Running ct. Let us add another factory method Create<strong>Model</strong>WithProbe to the<br />

Factory class in Bag<strong>Model</strong> that constrains the bag model by including the ElementRestriction<br />

and the Probe features.<br />

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

{<br />

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

"Bag<strong>Model</strong>", new Set("ElementRestriction","Probe"));<br />

}<br />

Figure 12.6 shows a partially explored part of the state machine of Create<strong>Model</strong>WithProbe<br />

composed with ProbeScenario and AddDeleteScenario, using mpv.<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!