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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Systems with Complex State 199<br />

The DoAction method makes a step according to the given input action. It may<br />

return either an output action or the special value null, which indicates that there is<br />

no immediate output action. You should implement the DoAction method to throw an<br />

exception if the input action fails. The Reset method should reset the implementation<br />

to its initial state. If the stepper cannot reset the implementation from its current<br />

state, it should throw an exception.<br />

Since we are not interested in testing multiple instances of BagImpl, we assume<br />

that the initial state of the stepper references a fixed instance of BagImpl that has<br />

been created initially.<br />

These are the action symbols that the stepper must handle:<br />

• An Add symbol that takes a string as an argument.<br />

• A Delete symbol that takes a string as an argument.<br />

• A Lookup Start symbol that takes a string as an argument, and a Lookup Finish<br />

symbol that takes an integer as an argument. The action Lookup Start(e) represents<br />

the invocation of the bag implementation’s Lookup method with input<br />

parameter e, and the action Lookup Finish(k) represents the return value k of the<br />

invocation.<br />

• A Count Start symbol and a Count Finish symbol that take an integer as an argument.<br />

The action Count Start() represents the invocation of the bag implementation’s<br />

implicit get Count method, and the action Count Finish(k) represents<br />

the return value k of the invocation.<br />

A stepper for BagImpl is shown in Figure 12.4. In order to map the stepper’s input<br />

actions to concrete inputs for the bag implementation, the stepper must extract the<br />

first argument of the input action a, using the indexer expression a[0] and a cast<br />

to string. The modeling library provides action arguments through a C# indexer,<br />

which accesses elements by subscripts. In order to construct the output actions that<br />

correspond to the return values of the lookup and count operations, the stepper uses<br />

the utility function Action.Create to create an output action from a given action<br />

name and arguments given as .NET values. (Appendix A.3 explains these and other<br />

facilities for working with action terms.)<br />

12.3 Strategies<br />

In a typical model, there are multiple possible actions enabled in any given model<br />

state. With offline test generation, the main idea is that the model is analyzed globally<br />

and a test suite is derived that provides a traversal of the model.<br />

The offline case is a special case of a more general form of testing where the<br />

tester has a strategy selecting the action to be executed next or what result is to be<br />

expected from the system under test. In addition to the model state, a tester also has<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!