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

Features<br />

<strong>We</strong> will model all of the features of the implementation Controller class (Chapter 3,<br />

Section 3.1).<br />

<strong>We</strong> must also model the controller’s environment: the timer, sensor, and supervisor<br />

(Chapter 3, Figure 3.1). This is necessary in order to model events realistically. In<br />

our sandbox implementation, simulated events were generated by the user (through<br />

the Simulator class, Figures 3.5 and 3.6) or by the test fixture (Figure 3.7). In the<br />

model, we cannot use a .NET timer as we did in the simulator, because the time-out<br />

events must be scheduled by the tools.<br />

Actions<br />

There is an action in the model program for every event handler in the implementation’s<br />

Controller class: Reset, Poll, and so on. The enabling conditions<br />

for these actions are the same as the guards in the implementation: ResetEnabled,<br />

PollEnabled, and so on. There is no action in the model corresponding to the implementation’s<br />

DispatchHandler method; its control structure is implicit in the enabling<br />

conditions.<br />

There is also an action for each kind of event that the reactive program handles. In<br />

the implementation, there is a single method ReceiveEvent with a cevent parameter<br />

that indicates what kind of event occured. Our several event actions correspond<br />

to different invocations of ReceiveEvent with different values for cevent. In the<br />

model, it turns out to be simpler to define a different action for each type of event,<br />

because each has a different enabling condition and makes different updates to the<br />

model state. In fact, there are more of these action methods than event types. For the<br />

Timeout event, we have the actions Timeout, TimeoutMsgLost, and TimeoutMsgLate.<br />

The additional code in our several event actions (compared to ReceiveEvent) is<br />

necessary because the model program must model the environment that generates<br />

events, in addition to the controller.<br />

The model program alternates between executing an event action and a handler<br />

action. <strong>We</strong> have to define a do-nothing handler NoHandler to model what happens<br />

when no handler is enabled in the implementation.<br />

Traces<br />

<strong>We</strong> write some sample traces to show how behaviors discussed in Chapter 3 are<br />

expressed in the action vocabulary we chose. The run coded in the test method<br />

named Typical (section 3.3) is expressed by this trace:<br />

Timeout();<br />

Reset();<br />

Message("99.9");<br />

CheckMessage();<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!