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

using System;<br />

using System.Collections.Generic;<br />

using N<strong>Model</strong>.Terms;<br />

using N<strong>Model</strong>.Execution;<br />

using N<strong>Model</strong>;<br />

namespace N<strong>Model</strong>.Conformance<br />

{<br />

public interface IStrategy<br />

{<br />

Set ActionSymbols { get;}<br />

IState CurrentState { get;}<br />

bool IsInAcceptingState { get;}<br />

void Reset();<br />

bool IsActionEnabled(Action action, out string reason);<br />

Action SelectAction(Set actionSymbols);<br />

void DoAction(Action action);<br />

}<br />

}<br />

Figure 12.5. The IStrategy interface.<br />

a tester state. For example, the tester may have a counter of how many individual test<br />

steps (transitions) have been made in total to be able to distinguish between different<br />

occurrences of the same model state. In the offline case the value of the counter is<br />

enough for the tester to know what action to select or to expect next, namely if the<br />

counter is n then the next action is the nth action in the test suite (assuming the test<br />

suite contains a single sequence of actions).<br />

With on-the-fly testing, the selection of actions is dynamic and happens during<br />

testing; there is no precomputed test suite and the full state machine does not need to<br />

be known in advance. The tester state needs to be rich enough to record information<br />

needed to select the next action. In particular, the tester state must have a reference<br />

to the current model state in order to know what actions are enabled. An action that<br />

is not enabled in the model must not be selected by the tester, because conformance<br />

to the model would be violated.<br />

A way to realize a particular on-the-fly tester is to implement a custom strategy.<br />

The ct tool can be provided with a custom strategy using the strategy option. A<br />

strategy is implemented by providing the IStrategy interface shown in Figure 12.5<br />

that is assumed to provide the following functionality:<br />

• The ActionSymbols property gets the set of all possible action symbols in the<br />

model.<br />

• The CurrentState property gets the current model 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!