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 Complex State 203<br />

After a couple of executions of ct we get another failure trace:<br />

TestResult(2, Verdict("Failure"),<br />

"Action ’Count_Finish(1)’ not enabled in the model<br />

Unexpected return value of finish action, expected: Count_Finish(2)<br />

Unexpected finish action",<br />

Trace(<br />

Count_Start(),<br />

Count_Finish(0),<br />

Delete(""),<br />

Add(""),<br />

Add("b"),<br />

Add(""),<br />

Delete("b"),<br />

Delete("b"),<br />

Count_Start(),<br />

Count_Finish(1)<br />

)<br />

)<br />

Here the error is that the last call to Count returns 1 instead of 2. Note that there<br />

must be two empty strings in the table at this point. By inspecting the implementation<br />

we can see that when an element is deleted, a case is missing for the situation when<br />

the count of the element that is deleted becomes 0. If this happens then the deletion<br />

should also remove the element from the table. It is left as an exercise to the reader<br />

to correct the two errors in the implementation and rerun ct.<br />

12.4 Coverage-directed strategies<br />

Coverage is a measure of how much testing has been done. <strong>Testing</strong> achieves better<br />

coverage by exercising the implementation more thoroughly. A custom strategy can<br />

be designed to achieve good coverage according to a measure chosen by the designer.<br />

The basic strategy provides random walks of a given number of steps, restarting<br />

from the initial state each time. Purely random selection of actions may be wasteful,<br />

and often one can do better. The basic idea is to keep a history of previously taken<br />

steps. Here we look at how to implement a customized strategy for a given model<br />

program that keeps track of a set of abstract coverage points. The algorithm that we<br />

are presenting here should be seen as an example of how to implement your own<br />

testing strategies, using the IStrategy and the <strong>Model</strong>Program interfaces as extension<br />

points of the modeling library.<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!