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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Instead of explaining the traversal algorithm here, we simply exhibit the results. 2<br />

Figure 8.1 shows the test suite generated by otg from the client/server contract model<br />

program developed in Chapter 5, Section 5.6, whose true FSM is shown in Chapter 7,<br />

Figure 7.1. This test suite was generated and stored in the file ContractTest.txt by<br />

the command:<br />

otg /r:ClientServer.dll ClientServer.Factory.Create ˆ<br />

/file:ContractTest.txt<br />

This test suite is itself an FSM; in fact, Figure 8.1 was created by this mpv commmand:<br />

mpv /testSuite:ContractTest.txt<br />

It is clear from Figure 8.1 that the test suite describes a collection of six sequences.<br />

Each sequence is a test case. The ct tool can interpret the contents of the test suite file,<br />

and, when harnessed to the implementation, can execute and check all the test cases.<br />

The test suite in Figure 8.1 describes many similar runs because it was generated<br />

from the true FSM of the contract model program, without using any scenario<br />

control. It is likely that a smaller test suite would be as effective in detecting defects,<br />

for the reasons explained in Chapter 7, Section 7.1.<br />

<strong>We</strong> can generate a smaller test suite by using scenario control. Let us generate a<br />

test suite from the client/server contract model program composed with the scenario<br />

machine developed in Chapter 7, Section 7.3.3. The FSM of the composition is<br />

shown in Figure 7.15. This command generates the test suite.<br />

otg /r:ClientServer.dll ClientServer.Factory.Create ˆ<br />

/fsm:Scenario.txt ˆ<br />

/file:ScenarioTest.txt<br />

Figure 8.2 shows the generated test suite. There is just a single run, because all<br />

the states and transitions in the FSM of the composition can be visited by traversing<br />

a single path from the initial state to the accepting state, including each of the loops<br />

in the middle of the FSM (Figure 7.15 in Chapter 7).<br />

Other traversal algorithms are possible. In addition to the postman tour, modelbased<br />

offline test generators sometimes provide random traversals, traversals that<br />

cover the shortest path to an accepting state (or some other interesting state), or<br />

traversals that achieve transition coverage but with an upper limit on the length of<br />

each test case (which generates more runs, but shorter runs, than does the postman<br />

tour). At the time of this writing, the otg tool provides none of these, but the modeling<br />

library could be used to write a custom offline test generator.<br />

2 The traversal algorithm is explained in several references cited in Further Reading (Chapter 9).<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!