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.

Systems with Finite <strong>Model</strong>s 121<br />

This code is inflexible. It is often better to separate the domains from the contract<br />

model program, so the same model program can be configured with different domains<br />

for different scenarios. Figure 7.5 shows how to use features to achieve this.<br />

In the contract model program, code the action method without a domain. Then, in a<br />

feature, code an action method with the same name, but include the domain. Leave<br />

the body of this action method empty. To select that domain, include that feature.<br />

When the combined action executes, the domain from the selected feature is used,<br />

and the body of the action method in the contract model program executes with<br />

a parameter value from that domain. (In this example the feature has no enabling<br />

conditions; the ones in the contract model program are sufficient.) Create different<br />

features that use different domains and include the one that generates the scenario<br />

you want. You must include one of these features; a model program cannot be<br />

explored (is not explorable) if there are parameters without domains.<br />

7.3 Composition<br />

Composition combines separate model programs into a new model program called<br />

the product. The product formed by composing model programs M1 and M2 is<br />

written M1 × M2 or M1∗M2. Composition is performed automatically by the analysis<br />

and testing tools when multiple model programs are named on the command line;<br />

the tools can then analyze or test from the product. You can also do composition<br />

in programs you write by calling the library. Composition can be used to build up<br />

complex model programs by combining simpler ones (as we shall see in Chapter 14).<br />

In this chapter we use it for scenario control.<br />

The next section explains how composition is done. The section after that describes<br />

some additional styles for coding model programs that make it easy to write<br />

scenarios for composition. In Section 7.3.3 we will return to using composition for<br />

scenario control.<br />

7.3.1 Understanding composition<br />

Recall that features are classes in the same model program (the same namespace),<br />

which may use the same state variables and are compiled into the same assembly.<br />

In contrast, we compose separate model programs, which can be in separate namespaces<br />

and can be compiled into separate assemblies. All of the tools accept any<br />

number of model programs; they form the product of all of them. No special coding<br />

is needed to prepare model programs for composition (no attributes, etc.). Any two<br />

(or more) model programs can be composed (although the product is not always<br />

useful, of course).<br />

The product of two or more model programs has all the state variables and all<br />

the actions of each of the composed programs. The key idea in composition is that<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!