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.

72 <strong>Model</strong> Programs<br />

that the sequence of actions coded in this method is not allowed by the model<br />

program. This means that the implementation is not able to execute this sequence.<br />

Simulation is the most limited and labor-intensive model-based analysis technique<br />

because it only considers one run at a time. To perform more thorough<br />

analyses – to detect the design errors discussed in Chapter 3, for example – we need<br />

to consider many different runs. For this, we use a more powerful analysis technique<br />

called exploration, which we will discuss in Chapter 6.<br />

<strong>We</strong> recommend that you simulate and explore your model program as you develop<br />

it, so you can check frequently that it behaves as you intend. There is no need to<br />

finish the model program first; you can begin analyzing as soon as you have coded<br />

a few actions. The mpv tool makes it easy, as we shall see in Chapter 6. But first, we<br />

present model programs for the two implementations in Part I.<br />

5.6 Case study: client/server<br />

In this section we model the client/server system discussed in Chapter 2. In this<br />

example, we have the implementation available to help us with preliminary analysis<br />

and coding.<br />

This example shows how a single model program can represent a distributed<br />

system with programs running on two computers connected by a network.<br />

5.6.1 Preliminary analysis<br />

The first activity in writing a model program is always a preliminary analysis.<br />

Recall that in preliminary analysis, we decide on a purpose for the model, select the<br />

features to include, and choose a level of abstraction by identifying the actions and<br />

state variables to represent in the model.<br />

Purpose<br />

The purpose of this model is to automatically generate and check test runs that can<br />

detect defects like the one described in Chapter 2, Sections 2.9 and 2.10.<br />

<strong>We</strong> will execute these tests in a configuration similar to the one where we executed<br />

the unit test described in Chapter 2, Section 2.8: asandbox where both the client<br />

and server are controlled by the test runner, and both execute in a single thread,<br />

interleaving their method calls in an order that conforms to their protocol (Chapter 2,<br />

Figure 2.2).<br />

<strong>We</strong> want a contract model that can generate all the runs that the client and server<br />

can successfully execute in the sandbox. By a “run,” we mean a session where both<br />

client and server create sockets, possibly exchange some messages, and then close<br />

their sockets. By “successfully execute,” we mean every method call returns, and no<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!