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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

<strong>Model</strong> programs need not have a small number of states and actions. State variables<br />

can be numbers, strings, objects, or other data types that can have a great many<br />

values. The actions can be method calls with arguments, which can also have a great<br />

many values. In that case, the number of states and transitions defined by the model<br />

program is effectively “infinite”: much too large to write down, or even to store in a<br />

computer. Then it is not possible to completely explore the true FSM. <strong>We</strong> will write<br />

and analyze such infinite model programs in Part III. In Chapter 11, we will show how<br />

to configure nonexhaustive exploration of infinite model programs, in order to perform<br />

analyses that are incomplete, but still useful (we will finitize the analysis instead<br />

of the model). But here in Part II, we only consider model programs where we can<br />

completely explore the true FSM. That is why we emphasized finitizing the model<br />

programs in Chapter 5.<br />

6.2 Exploration<br />

Recall that exploration automatically generates an FSM from a model program. The<br />

FSM can then be used for visualization, analysis, and offline test generation. In the<br />

following subsections we explain how to explore a model program with the library<br />

and tools.<br />

6.2.1 Accessing the model program<br />

To work with the library or any tool created from it (including mpv, otg, orct), a<br />

model program must provide a factory method that creates a Library<strong>Model</strong>Program<br />

object from the compiled model program assembly. All tools access the model<br />

program indirectly, by invoking the methods of this object.<br />

<strong>We</strong> recommend putting the factory method in its own factory class. The factory<br />

class always has the same form; only a few identifiers must be changed for each<br />

particular model program. Figure 6.3 shows the factory class from our newsreader<br />

model program.<br />

The factory class appears in the same namespace as the model program and must<br />

be compiled in the same assembly. For example, the code in Figure 6.3 appears in<br />

the same NewsReader namespace as the code in Chapter 5, Figures 5.4 and 5.5. The<br />

factory class must be declared public static. (The class or classes that contain<br />

the state variables and action methods of the model program need not be public;<br />

we recommend they have the default private access.) <strong>We</strong> usually name the factory<br />

class Factory and the factory method Create, but this is not required. In the body<br />

of the factory method, in the Library<strong>Model</strong>Program constructor, the argument of<br />

the typeof operator must be the same class, Factory here. The second argument<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!