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.

84 <strong>Model</strong> Programs<br />

Timeout();<br />

Poll();<br />

Message("100.0");<br />

CheckMessage();<br />

Command();<br />

Calibrate();<br />

Compare this trace to the test method (Figure 3.7) and the test output (Section 3.3).<br />

The calls to ReceiveEvent in the test method are modeled by different actions for<br />

each kind of event: Timeout, Message, and Command (the Exit event is not modeled).<br />

The calls to DispatchHandler are modeled by the actions for each handler: Reset,<br />

Poll, and Calibrate.<br />

The simulation in Section 3.4 that shows an unsafe run, labeled OutOfRangeMessageWhenIdle,<br />

is expressed by this trace:<br />

Timeout();<br />

Reset();<br />

Message("99.9");<br />

CheckMessage();<br />

Timeout();<br />

Poll();<br />

TimeoutMsgLate();<br />

ReportLostMessage();<br />

Message("999.9");<br />

NoHandler();<br />

Command();<br />

Calibrate();<br />

In this trace, two different time-out actions appear: Timeout and TimeoutMessageLate.<br />

The NoHandler action here indicates that no handlers are enabled after the<br />

second message.<br />

State variables<br />

In this example, the parts of the model program that model the Controller class are<br />

similar to the implementation. The model program has these control state variables,<br />

which also occur in the implementation: cevent, the most recent event; waitfor, the<br />

kind of event the controller is waiting for; and sensor, the inferred sensor status.<br />

The model program has additional control state variables that are not in the<br />

implementation. TimeoutScheduled and MessageRequested model the timer and the<br />

sensor to ensure that events are modeled realistically. They are tested by the enabling<br />

conditions for the event actions, and are updated by the event actions. Finally, the<br />

phase variable controls the alternation of events and handlers.<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!