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.

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

action method. Before calling each action method, the test method calls NUnit’s<br />

IsTrue assertion to check the enabling condition. These checks ensure that the run<br />

will succeed only if it executes a sequence of actions that is allowed by the model<br />

program. If it attempts to execute a forbidden sequence, it will fail.<br />

The test method shown in Figure 5.6 programs a run that the model program<br />

should be able to execute. It encodes this sequence of actions:<br />

ShowTitles(); SortByFirst(); SortByMostRecent(); ShowText();<br />

This run succeeds. It produces this output:<br />

Included categories: AllowedRun<br />

.Topics, WithText, ByMostRecent: ShowTitles<br />

Topics, TitlesOnly, ByMostRecent: SortByFirst<br />

Topics, TitlesOnly, ByFirst: SortByMostRecent<br />

Topics, TitlesOnly, ByMostRecent: ShowText<br />

Tests run: 1, Failures: 0, Not run: 0, Time: 0.080 seconds<br />

<strong>We</strong> also code a run that the model program should not be able to execute:<br />

ShowTitles(); SortByFirst(); SortByFirst(); ShowText();<br />

The model program should not be able to execute this run because there are two<br />

SortByFirst actions in succession. The second of these is not enabled (in the<br />

implementation, this option is not available in this state). The run fails, confirming<br />

that the model program cannot execute this run:<br />

Included categories: ForbiddenRun<br />

.Topics, WithText, ByMostRecent: ShowTitles<br />

Topics, TitlesOnly, ByMostRecent: SortByFirst<br />

F<br />

Tests run: 1, Failures: 1, Not run: 0, Time: 0.080 seconds<br />

Failures:<br />

1) NewsReader.Tests.ForbiddenRun :<br />

at NewsReader.Tests.ForbiddenRun()<br />

This test failure does not indicate that the model program is incorrect. <strong>We</strong> are<br />

not testing the model program here; we are executing the model program in order<br />

to simulate the implemention. <strong>We</strong> are only using the test tool because it is more<br />

convenient to write two tests than to write two applications. The failure here indicates<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!