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.

Systems with Finite <strong>Model</strong>s 129<br />

Recall that the purpose of scenario control is to eliminate runs allowed by a<br />

contract model program that are not pertinent to the particular issue we wish to<br />

analyze or test. The unwanted runs can be eliminated by composing the contract<br />

model program with a scenario model program that encodes the runs we wish to<br />

see. It is often convenient to code the scenario model program as an FSM. Recall<br />

that composition has the effect of selecting only the runs that are allowed by both<br />

composed programs. If there is a particular sequence of actions you want to see<br />

in the product, put that sequence in the scenario model program. If there are other<br />

actions you would allow to interleave in the product, do not mention those actions<br />

in the scenario model program. If there are actions you want to eliminate from the<br />

product, include those actions in the vocabulary of the scenario model program but<br />

do not write any transitions that use them. This has the effect of disabling those<br />

actions in all states.<br />

There is a typical scenario that we often want to use for testing: first, a sequence of<br />

setup actions, then several (or many) interleaved test actions, and finally, a sequence<br />

of cleanup actions. Figure 7.14 shows a model program for generating such a<br />

scenario from the client/server model program. Compare this to the true FSM for<br />

the contract model program (Figures 7.1, and 7.2). The setup and cleanup sequences<br />

in the scenario model program select one run through the many paths allowed by the<br />

contract model program. The scenario model program does not mention the send<br />

and receive actions; those are the test actions that are allowed to interleave.<br />

This command displays the test scenario model program composed with the<br />

contract model program:<br />

mpv /fsm:Scenario.txt /r:ClientServer.dll ClientServer.Factory.Create<br />

Figure 7.15 shows the result. The setup and cleanup sequences from the scenario<br />

model program also appear in the product. The loops in the middle of the diagram<br />

represent the interleaving of the test actions, send and receive. <strong>We</strong> will use this<br />

product in Chapter 8 to generate and check tests that reveal the defect we discussed<br />

in Chapter 2.<br />

7.4 Choosing among options for scenario control<br />

There are three ways to control the scenarios of a model program: enabling conditions,<br />

features, or composition. <strong>We</strong> recommend that the model program should<br />

be a specification or contract, so its enabling conditions should permit all allowed<br />

runs, not just particular scenarios. Scenario control should be separated out with<br />

features or composition, so the same contract model program can analyze or test<br />

different scenarios. Features can access the model program state, so use features for<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!