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.

28 <strong>Why</strong> <strong>We</strong> <strong>Need</strong> <strong>Model</strong>-<strong>Based</strong> <strong>Testing</strong><br />

A realistic test of a client/server system tests one end at a time, the client or the<br />

server. From the point of view of each end, the other end is nondeterministic: its<br />

behavior cannot be predicted. This poses practical problems for coding tests. Here<br />

we avoid these problems by creating a sandbox, a testing environment where we<br />

remove the nondeterminism by controlling both client and server. Both can run on<br />

the same computer, and use the localhost IP address. In fact, we can call both client<br />

and server methods from the same test method. <strong>We</strong> call the methods in a single<br />

thread, taking care to interleave the method calls in an order that conforms to the<br />

protocol (Figure 2.2). This test exercises most of the methods in the Client and<br />

Server classes. However, it omits the Temperature class and assigns a temperature<br />

value in the test code instead. The assertions check that the command sent by the<br />

client is received by the server, and the temperature sent by the server is received by<br />

the client. The test also writes a progress message to the console, which is displayed<br />

by the test runner.<br />

Here is a test run.<br />

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

...<br />

Included categories: ClientServer<br />

.Server sent 212.0, client received 212.0<br />

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

The test succeeds and the expected progress message appears. Can we conclude<br />

from this that the applications will work?<br />

2.9 Failures in the field<br />

One day we connect up our measurement system (as in Figure 2.1), start the server<br />

and the client, and leave them running. All goes well until the temperature reaches<br />

100 ◦ . At the client, we see:<br />

2006-11-07 16:07:01Z Temperature server at port 8023 reports 99.8 F<br />

2006-11-07 16:07:11Z Temperature server at port 8023 reports 99.9 F<br />

2006-11-07 16:07:21Z Temperature server at port 8023 reports 100.0 F<br />

2006-11-07 16:07:31Z Temperature server at port 8023 reports 0.0 F<br />

2006-11-07 16:07:41Z Temperature server at port 8023 reports 99.9 F<br />

2006-11-07 16:07:51Z Temperature server at port 8023 reports 99.8 F<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!