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.

0<br />

B(2) C()<br />

1<br />

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

Figure 7.12. M1 × M2 projected onto M2.<br />

FSM(0, AcceptingStates(), Transitions(t(0,A(),1), t(1,B(2),2)))<br />

Figure 7.13. M1 as an FSM text file.<br />

executes an action of M2, that transition is added to the projection onto M2. In this<br />

example the projection of M1 × M2 onto M2 looks like the original M2 (Figure 7.7),<br />

except the action B() from M2 is replaced by the action B(2) from the product.<br />

Sometimes the projection has fewer transitions than the original program. This is<br />

significant when composition is used for analysis (Section 7.5).<br />

7.3.2 FSMs for scenario control<br />

<strong>We</strong> often write a scenario model program to compose with a contract model program<br />

for scenario control. It is often convenient to express a scenario model program as<br />

an FSM. The library and tools support several styles for coding model programs.<br />

All of the examples so far have used just one of these styles, the style introduced<br />

in Chapter 5 and described in Appendix A. In this section we introduce two more<br />

styles that make it easier to code FSMs for scenario control.<br />

First we show how to code an FSM in the familiar style. Figure 7.13 shows<br />

program M1 from Section 7.3.1, coded in C#, in the same style as the other model<br />

programs we have seen. There is just a single state variable, which corresponds<br />

to the state numbers shown in the state bubbles in Figure 7.6. <strong>We</strong> call a program<br />

coded in this style a library model program. There is a factory method that invokes<br />

the constructor for the Library<strong>Model</strong>Program class, which is derived from the<br />

<strong>Model</strong>Program base class. To display the FSM, compile the program and invoke mpv:<br />

mpv /r:M1.dll M1.Factory.Create<br />

To compose and display two model programs, for example, M1 and M2 as in<br />

Figure 7.8,invokempv with both:<br />

mpv /r:M1.dll /r:M2.dll M1.Factory.Create M2.Factory.Create<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!