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.

148 <strong>Testing</strong> Closed Systems<br />

B()<br />

A()<br />

0 1<br />

C()<br />

D()<br />

Figure 8.6. Transition coverage versus path coverage.<br />

2<br />

The number of messages sent by each test case is a consequence of the traversal<br />

algorithm used by the offline test generator tool, otg. The postman tour algorithm<br />

achieves full transition coverage: every transition in the FSM is taken at least once.<br />

The postman tour is minimal: the total number of transitions in the test suite is the<br />

minumum needed to achieve transition coverage; the algorithm avoids traversing<br />

the same transition more than once, if that is possible. This explains the shapes of<br />

the test suites displayed in Figures 8.1 and 8.2. (In the second test suite, it is pure<br />

luck that the longer message happens to be sent first.)<br />

These examples confirm that minimal transition coverage is not sufficient to<br />

expose some defects. Consider the simple example in Figure 8.6. Minimal transition<br />

coverage will generate two test cases: A(),B(),C() and A(),D(). The assumption<br />

is that the model state really does determine the behavior; there is no need to<br />

cover every path; D() will not be affected by B() preceding it. This assumption<br />

can be false if the implementation has hidden state that is not represented in the<br />

model. In that case, we should also attempt some amount of path coverage by also<br />

testing the paths A(),B(),D(), and maybe even A(),B(),B(),D(). In our client/server<br />

implementation, the hidden state is the client’s receive buffer.<br />

These are limitations of minimal transition coverage, not offline test generation<br />

in general. <strong>We</strong> can imagine an offline test generator with a more thorough traversal<br />

algorithm. But the requirement in offline testing that the entire test suite must be<br />

computed in advance discourages thorough coverage. Moreover, it is not feasible<br />

to explore the true FSM of many “infinite” model programs at all. And, when the<br />

implementation exhibits nondeterminism, it is wasteful to compute paths that may<br />

never be taken. For these reasons, the tools emphasize on-the-fly testing, where the<br />

tests are computed as the test executes. In contrast with the limited choice of traversal<br />

algorithms built into the otg tool (just one at this writing), the ct tool provides rich<br />

opportunities for testers to program their own on-the-fly testing strategies, as we<br />

shall see in Chapters 12 and 16.<br />

8.6 Exercises<br />

1. Write a stepper for the three newsreader implementations you wrote for the<br />

problems in Chapter 5. Generate a test suite from the newsreader model program<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!