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.

74 <strong>Model</strong> Programs<br />

ServerSend(212.0);<br />

ClientReceive(); // should return 212.0<br />

ClientClose();<br />

ServerCloseConnection();<br />

ServerClose();<br />

Here server.Socket in the implementation is modeled by ServerSocket in the<br />

model program, and so on. The arguments of Bind, Connect, and the client’s Send<br />

in the implementation are not needed in the model program. <strong>We</strong> use a comment to<br />

indicate the expected return value of ClientReceive in this trace. <strong>We</strong> explain how<br />

return values are handled in the N<strong>Model</strong> framework in Chapter 8, Section 8.2.<br />

State variables<br />

In the implementation, there are classes for the client and server, and particular<br />

clients and servers are instances. Any program with instances is potentially “infinite,”<br />

because it can create an unlimited number of them. <strong>We</strong> must make our model program<br />

finite. In our tests, we will only have one client and one server, so instances are not<br />

needed. In our model program, the state variables are the static variables needed to<br />

model just one client and one server. This is an example of data abstraction. A model<br />

program where all variables are static can model an implementation with instances<br />

and can be connected in a test harness with that implementation (Chapter 8).<br />

Recall that state variables can store control state that determines the sequence<br />

of actions. In this example, there are two kinds of constraints on that sequence.<br />

Sockets must be created, connected, and closed according to the protocol shown<br />

in Chapter 2, Figure 2.2. And, the send and receive actions must alternate, always<br />

beginning with a send action. Therefore we have three state variables for the control<br />

state. Two keep track of each partner’s step in the protocol: clientSocket and<br />

serverSocket. The third synchronizes send and receive actions: phase. These three<br />

variables do not correspond closely to any variables in the implementation. In the<br />

implementation, the ordering of method calls is coded in the applications that call<br />

them.<br />

Recall that state variables can hold data state that stores the arguments and return<br />

values of actions. In this example, the data state is the most recently acquired<br />

temperature. <strong>We</strong> store the data state in a single state variable. It turns out to be most<br />

convenient to use the client’s receive buffer clientBuffer.<br />

The temperature is a number. All numeric types are “infinite”: not mathematically<br />

infinite, but too large to store every value. Any program that uses numbers is<br />

potentially “infinite” (i.e., it has an “infinite” state space). To finitize our model, we<br />

must limit it to a finite collection of temperatures; the smaller, the better. <strong>We</strong> decide<br />

to use just two. <strong>We</strong> suspect that there might be defects in the implementation that<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!