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 67<br />

5.4.1 Program structure<br />

A model program must include using statements to use the namespaces of the modeling<br />

library N<strong>Model</strong>. A typical model program uses the N<strong>Model</strong>, N<strong>Model</strong>.Attributes,<br />

and N<strong>Model</strong>.Execution namespaces. All of these are provided by the library<br />

N<strong>Model</strong>.dll. A model program is compiled to a library, for example, by a command<br />

like this one (where DEVPATH is an environment variable that stores the path to<br />

the directory that contains the library, e.g., C:\Program Files\N<strong>Model</strong>\bin):<br />

csc /t:library /r:"%DEVPATH%\N<strong>Model</strong>.dll" NewsReaderUI.cs<br />

<strong>We</strong> code each model program in its own namespace. A model program consists<br />

of the actions and variables defined by the types declared in its namespace. The<br />

namespace name is the model program name: NewsReader in this example. A model<br />

program can include more than one class (or other types); this simple example has<br />

just one class.<br />

NewsReader declares some variables to store the state, some methods to implement<br />

the actions, and some methods to test when each action is enabled. That’s all there<br />

is to a model program. A model program does not have a main method or any other<br />

control structure for invoking the actions.<br />

<strong>We</strong> recommend coding model programs with no access modifiers, so most types<br />

and members have the default private access. The tools can access private types and<br />

members (using a mechanism we will describe in Chapter 6).<br />

5.4.2 State variables<br />

The state variables of the model program are the static fields and instance fields declared<br />

in the model program’s namespace. Public and nonpublic fields are included.<br />

Fields inherited from base classes (outside of the model namespace) are included.<br />

In our example there are only three state varables. Each has only a few values so<br />

we declare an enumerated type for each.<br />

enum Page { Topics, Messages };<br />

enum Style { WithText, TitlesOnly };<br />

enum Sort { ByFirst, ByMostRecent };<br />

In our examples all of the state variables are static variables. <strong>We</strong> declare all three,<br />

and assign the initial state in the declarations.<br />

static Page page = Page.Topics;<br />

static Style style = Style.WithText;<br />

static Sort sort = Sort.ByMostRecent;<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!