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.

Overview 31<br />

)<br />

)<br />

ClientSocket(),<br />

ClientConnect(),<br />

ServerAccept(),<br />

ServerSend(double("100")),<br />

ClientReceive_Start(),<br />

ClientReceive_Finish(double("100")),<br />

ServerSend(double("99.9")),<br />

ClientReceive_Start(),<br />

ClientReceive_Finish(double("99"))<br />

The message indicates that this test failed because the value 99 returned by the<br />

client’s receive method differs from the expected return value 99.9 computed by the<br />

model program. The tool reports the execution of the automatically generated test<br />

run in a syntax that is easy to understand but differs from that of C#. This syntax<br />

expresses the tool’s internal representation of method calls and returns as data<br />

structures called terms, which provide advantages that we will explain in chapters<br />

to come. Be assured that you will write model programs and program the tools in<br />

ordinary C#.<br />

This chapter has described the effects of a trivial defect in the code, a mere<br />

typographical error. <strong>We</strong> also have analysis methods that can detect the deeper errors<br />

that arise during specification or design, as we shall see in the next chapter.<br />

2.13 Exercises<br />

1. (Libraries, applications). Write new server and client programs, Probe and<br />

Sampler, that use our Server and Client classes, respectively. In this protocol,<br />

the server starts first, and waits for a connection from a client. The server<br />

responds by immediately sending back the temperature, then closing the connection.<br />

The client reads the temperature, and exits. The server may wait for<br />

another client to connect, or it may also exit.<br />

2. (Libraries). Consider the choice of the double type for the datum parameter of<br />

Server.Send and the return type of Client.Receive. Did this choice contribute<br />

to the failures (Section 2.9)? What alternatives might have been chosen? Discuss<br />

the implications of library design for unit testing.<br />

3. (Alternatives to unit testing). The defect discussed in this chapter was not exposed<br />

by the unit tests, but evidence of failures appeared in the application program<br />

output (Section 2.9). Could you write software to detect such failures automatically?<br />

Discuss the advantages and disadvantages of unit testing, compared to<br />

analyzing log files, for detecting defects.<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!