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 Finite <strong>Model</strong>s 69<br />

conditions, preconditions, orguards. Enabling conditions are the control structures<br />

of model programs. Writing enabling conditions is the only way to control the<br />

sequence of actions that can occur when a model program executes. When coding<br />

enabling conditions, it is helpful to refer to the sample traces you wrote during<br />

preliminary analysis.<br />

An enabling condition is a Boolean method that returns a bool value (a Boolean<br />

method is sometimes called a predicate). The enabling conditions of an action<br />

method have the same name as the action method, with the added suffix Enabled.<br />

An action method that has no enabling condition is always enabled (as if it had an<br />

enabling condition that always returned true).<br />

An enabling condition describes a set of states: all the states where it returns true.<br />

In this example, the enabling condition for the ShowTitles action method (described<br />

before) is ShowTitlesEnabled. It expresses that ShowTitles is enabled in all states<br />

where the page is a Topics page and the style is WithText. In this model program,<br />

there are two such states, where the third state variable sort takes on both of its two<br />

possible values.<br />

static bool ShowTitlesEnabled()<br />

{<br />

return (page == Page.Topics && style == Style.WithText);<br />

}<br />

Enabling conditions may have parameters, which correspond to the parameters<br />

of its action method. The parameters in the two methods are matched up by order,<br />

so the first parameter in each must have the same type (etc.), and they are alwayes<br />

called with the same arguments (the tools ensure this). An enabling condition may<br />

have fewer parameters than its action method. An enabling condition may use its<br />

parameters, as well as the state variables, to compute its return value.<br />

An action method may have more than one enabling condition by overloading<br />

(they have the same name but different parameters). All of the enabling conditions<br />

must be true to enable the action. A static enabling condition method may be used<br />

for an instance-based action method (Chapter 15).<br />

An enabling condition must be a pure method: it can only return true or false;it<br />

must not have any side effects that update state variables or parameters. An enabling<br />

condition can include calls to helper methods, provided that those methods are also<br />

pure.<br />

You can code the enabling conditions of several action methods such that more<br />

than one action is enabled in some states. For example, in our initial state both<br />

SelectMessages and ShowTitles are enabled. This is typical. Our model program<br />

exhibits nondeterminism: it is not possible to predict (from the model program itself)<br />

which of the enabled actions will be invoked. Any enabled action can be chosen at<br />

run time by the tool that executes the model program. A model program that exhibits<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!