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.

132 Structuring <strong>Model</strong> Programs with Features and Composition<br />

this way: the calibrate action should not follow the arrival of a message containing<br />

an out-of-range temperature. And, the liveness requirement is: the calibrate action<br />

should follow the arrival of a command. A property expressed in this way, by<br />

describing the ordering of actions, is a temporal property.<br />

Scenario model programs can express temporal properties, and composition can<br />

check them. Compose the contract model program with the scenario model program<br />

that expresses the property. Examine the projection of the product onto the scenario.<br />

If the projection is complete (it contains all of the transitions of the original scenario<br />

model program), then the contract model program can execute that scenario, and<br />

you will be able to find the runs of the scenario in the product. If the projection is<br />

incomplete (if it is missing some transitions), then the contract model program cannot<br />

execute that scenario, and you will not find any runs of the scenario in the product.<br />

Notice how this use of composition differs from scenario control, where we write<br />

a scenario that we want the contract model program to execute, that we assume it<br />

can execute. For analysis, we write a scenario that the contract model program may<br />

not be able to execute; that is what we want to find out.<br />

Let’s look at some examples. First, we consider an example where the scenario<br />

model program describes exactly one run. The analysis tells us whether the contract<br />

model program can execute that run; it provides the same information as simulation<br />

(Chapter 5, Section 5.5) or interactive exploration (Chapter 6, Section 6.2.3), but<br />

may be easier to set up and repeat.<br />

To make this easy to understand, we return to the simple news reader example. Let<br />

us see what happens when the contract model program cannot execute the scenario.<br />

<strong>We</strong> choose the run that we simulated in Chapter 5:<br />

ShowTitles(); SortByFirst(); SortByFirst(); ShowText();<br />

<strong>We</strong> encode this run as a scenario in an FSM text file with these contents:<br />

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

t(0,ShowTitles(),1), t(1,SortByFirst(),2), t(2,SortByFirst(),3),<br />

t(3,ShowText(),4)),<br />

Vocabulary("ShowTitles","ShowText","SelectMessages","SelectTopics",<br />

"SortByFirst","SortByMostRecent"))<br />

This FSM text file contains an entry at the end that defines the vocabulary of the<br />

scenario machine, the names of all its actions. If this entry is omitted, the vocabulary<br />

is understood to be the actions that appear in the transitions. Here we need to list the<br />

vocabulary because it includes actions that do not appear in any of the transitions<br />

of this particular scenario. When we use composition to check whether the contract<br />

model program can execute a particular run, we must include the whole vocabulary<br />

of the contract model program in the scenario model program. In the product, any<br />

actions of the contract model program that do not appear in the scenario vocabulary<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!