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.

42 <strong>Why</strong> <strong>We</strong> <strong>Need</strong> <strong>Model</strong>-<strong>Based</strong> Analysis<br />

this test, we do not just check a result at the end, we check that the entire run –<br />

the whole sequence of events and handler invocations – is what we intend. It is not<br />

clear how to use NUnit assertions to achieve this, so we code the test method to<br />

query the tester (the human user). The tester must watch the test output and make<br />

the judgment whether the test succeeded or failed, so this test is not fully automated.<br />

Executing this test in nunit-console produces this output. The lines that begin<br />

with a question mark ? are written by ReceiveEvent; they report the type of event<br />

that occured, the type of event that the controller expected (the waitfor variable),<br />

and whether the sensor is considered to be erroneous (the sensor variable). The<br />

indented lines are written by the handler methods; they indicate which handler ran,<br />

and the data the handler used. This test succeeds. The sensor status changes from<br />

Error to OK after a valid message is received. After that, the controller carries out a<br />

command to compute the calibration factor.<br />

> nunit-console /include=Typical Tests.dll<br />

...<br />

Included categories: Brief<br />

.?Timeout, Timeout, Error<br />

Reset<br />

?Message ’99.9’, Message, Error<br />

CheckMessage ’99.9’, compare to 99.9, OK<br />

?Timeout, Timeout, OK<br />

Poll<br />

?Message ’100.0’, Message, OK<br />

CheckMessage ’100.0’, compare to 99.9, OK<br />

?Command, Timeout, OK<br />

Calibrate ’100.0’<br />

?Exit, Timeout, OK<br />

Did the expected handlers run? [y/n] y<br />

Tests run: 1, Failures: 0, Not run: 0, Time: 2.353 seconds<br />

<strong>We</strong> write a similar test method where the reported temperature differs too much<br />

from the previous sample. The controller should not calculate a calibration factor,<br />

but should reset the sensor instead. This test also succeeds. After the message with<br />

the out-of-range temperature, the command to calibrate is not executed; instead, no<br />

handler runs. But then the controller resets the sensor, and after a more reasonable<br />

temperature is received, the controller resumes carrying out calibrate commands.<br />

> nunit-console /include=OutOfRangeMessage Tests.dll<br />

...<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!