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.

68 <strong>Model</strong> Programs<br />

Parameters and local variables in the model program are not state variables (there<br />

are none in this example).<br />

Sometimes it is useful to exclude a field from state for debugging or other<br />

purposes. The [ExcludeFromState] attribute can be used to annotate fields that<br />

should not be part of state. Fields excluded from the set of state variables must have<br />

no effect on the behavior of the model.<br />

5.4.3 Action methods<br />

The actions of the model program are methods annotated with the [Action] attribute.<br />

<strong>We</strong> call these methods action methods.<br />

Each action method must express how the action changes the state (or leaves it<br />

unchanged). Usually, the body of an action method computes the next state from<br />

the current state, by assigning one or more state variables. These assignments are<br />

sometimes called updates and an action method is sometimes called an update rule.<br />

Here is the ShowTitles action method from this example. It causes the titles only<br />

to be displayed on Topics pages by setting the style state variable to TitlesOnly.<br />

[Action]<br />

static void ShowTitles()<br />

{<br />

style = Style.TitlesOnly;<br />

}<br />

In addition, an action method may consume input or produce output. It is often<br />

useful for an action method to return a value, but this is not required. An action<br />

method may have parameters. (In this example, none of the action methods performs<br />

input or output, returns a value, or has parameters.)<br />

An action method can be a static method or an instance method (Chapter 15). (In<br />

this example, they are all static.)<br />

Action methods cannot be overloaded; each action method must have a different<br />

name.<br />

The action methods must all be at top level: the model program only defines<br />

them; it cannot call them.<br />

A model program can also contain helper methods that do not represent actions.<br />

Any code in the model program can call a helper method. (There are no helper<br />

methods in this example.)<br />

5.4.4 Enabling conditions<br />

In addition to action methods, a model program has methods that check when<br />

each action method is enabled (allowed to be invoked). These are called enabling<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!