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.

100 Exploring and Analyzing Finite <strong>Model</strong> Programs<br />

public static class Factory<br />

{<br />

public static <strong>Model</strong>Program Create()<br />

{<br />

return new Library<strong>Model</strong>Program(typeof(Factory).Assembly, "NewsReader");<br />

}<br />

}<br />

Figure 6.3. Newsreader model program: factory class with factory method.<br />

is a string that contains the name of the model program namespace, NewsReader<br />

here.<br />

To invoke a tool on a model program, reference the assembly that contains the<br />

compiled model program, and provide the fully qualified name of the factory method<br />

in that assembly. This command invokes mpv on the NewsReader model program. 1<br />

mpv /r:NewsReaderUI.dll NewsReader.Factory.Create<br />

6.2.2 Exhaustive exploration and visualization<br />

When the mpv tool is invoked on a finite model program, it exhaustively explores<br />

the model program, generates its true FSM, and displays its state transition graph.<br />

For example, invoking mpv on NewsReader (as in the command earlier) displays the<br />

graph in Figure 6.4.<br />

The graph generated by mpv looks similar to Figure 6.2, but not exactly the same.<br />

In Figure 6.2, each node is labeled by the values of all the state variables in that<br />

state. This does not generalize to many state variables, so mpv simply labels each<br />

node with a number. The initial state is always number zero but the other numbers<br />

are arbitrary. The mpv tool provides a state viewer panel that shows all of the state<br />

variables and their values in the selected node. This enables mpv to be used as a kind<br />

of debugger for model program that can be run forward or backward. 2<br />

Although Figures 6.2 and 6.4 do not look exactly the same, they both represent<br />

the same FSM. The positions of nodes and links can be quite sensitive to the choice<br />

of display options and other factors, so graphs that appear different at first glance<br />

can be diagrams of the same FSM. Graphs you generate (from the same model<br />

programs) might not look much like the figures in this book. It is the labels on the<br />

links and the connections between the nodes that are significant, not the positions<br />

of the nodes and links, nor the numbers on the nodes.<br />

1 A complete command reference for mpv and the other tools appears in Appendix B.<br />

2 In mpv, click on a node to select it. Then use the n key to step forward and p to step backward.<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!