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.

82 <strong>Model</strong> Programs<br />

the set of argument values for the parameter. When a tool executes the action method,<br />

it will choose one element from this set to assign to that parameter. A domain can<br />

also be a field or a property. The domain can depend on the state (it can return<br />

different sets of values in different states).<br />

static Set Temperatures()<br />

{<br />

return new Set(Temp1, Temp2);<br />

}<br />

Here the domain method always returns the same set. A domain method can return a<br />

set that is computed from the state. Set is a C# generic collection type that is provided<br />

by the modeling library (Chapter 10). Here identifies the type of the<br />

elements of the set, which must match the type of the parameter in the action method.<br />

In this example we code the domain in the model. In Chapter 7 we show how to<br />

code the domain separately from the model (which makes it easier to use different<br />

domains with the same model).<br />

Now that we have a model program, we must validate it. Since we intend to use<br />

it for testing, we must show that it behaves as the implementation is supposed to<br />

behave. <strong>We</strong> can do a few simulation runs as we did in Section 5.5, simulating the<br />

test run of Chapter 2, Section 2.8, for example. <strong>We</strong> will analyze this model program<br />

more thorougly in Chapter 6 and use it to generate and check tests in Chapter 8.But<br />

first we present another model program.<br />

5.7 Case study: reactive program<br />

In this section we model the reactive system discussed in Chapter 3. This example<br />

shows how a single model program can represent a reactive program interacting<br />

with its environment.<br />

5.7.1 Preliminary analysis<br />

Purpose<br />

The purpose of this model program is to be the subject of a design analysis that<br />

can reveal the design errors that we discovered by testing in Chapter 3, Sections 3.4<br />

and 3.5.<br />

<strong>We</strong> also plan to use this model program for testing. After the design errors are<br />

corrected in the model program, we will be able to use the corrected model program<br />

to generate and check tests for the revised implementation (which still might have<br />

defects).<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!