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.

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

7.2.1 Defining features<br />

To define a feature, declare its state variables, action methods, and enabling methods<br />

in a class. The feature name is the class name. Label the class with the [Feature]<br />

attribute.<br />

Each feature can be selectively included or excluded from the model program.<br />

Classes that are not labeled with the [Feature] attribute are always included. State<br />

variables that are declared within a feature should only be used by that feature. State<br />

variables that are used by more than one feature should be declared in a class that is<br />

not a feature, so they will always be included.<br />

Figure 7.3 shows excerpts from a version of the client/server model program<br />

where the client and server are separate features (compare to the original version in<br />

Chapter 5, Figures 5.7–5.10). All of the state variables are used by both the client<br />

and the server, so they remain in the ClientServer class, which is not a feature. The<br />

state variables are declared internal to make them accessible in the feature classes.<br />

The action methods and enabling conditions of the client and server are declared in<br />

the new Client and Server classes, which are features.<br />

7.2.2 Including or excluding features<br />

Features are included in a model program by naming them in the Library<strong>Model</strong>-<br />

Program constructor (Chapter 6, Section 6.2.1). This constructor has an optional<br />

third argument, a set of strings that name the features to include. If this argument<br />

is omitted, all features are included. You can write several factory methods, where<br />

each one names a particular combination of features. When you invoke a tool, use<br />

the factory method that names the features you want to include.<br />

In Figure 7.3, the factory method CreateServerOnly names the server feature but<br />

not the client. This command runs mpv on the client/server model program with just<br />

the server feature included.<br />

mpv /r:ClientServer.dll ClientServer.Factory.CreateServerOnly<br />

Figure 7.4 shows the diagram that mpv displays. The client feature was excluded<br />

from the model program, so only a few server actions are enabled (the ones that do<br />

not involve communication with the client).<br />

7.2.3 Combining features<br />

Features can be combined to model interacting features in the implementation, or<br />

to achieve scenario control. To combine features, give some of their action methods<br />

the same names. Action methods in classes that are not features (which are always<br />

included in the model program) can also have the same names. All of the action<br />

methods that have the same name are parts of the same action; they are executed<br />

together. The combined action is enabled only when all the enabling conditions for<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!