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.

30 <strong>Why</strong> <strong>We</strong> <strong>Need</strong> <strong>Model</strong>-<strong>Based</strong> <strong>Testing</strong><br />

different methods from several classes, and observe the effects of each method. In<br />

this example, we had to execute several methods in the correct sequence to set up<br />

the client/server connection before we could execute the defective code. Even then,<br />

executing the defective code did not cause a failure immediately. The defective code<br />

affected storage (or state), so the failure did not occur until later. Such defects cannot<br />

be exposed by typical unit tests (as in Section 2.6), where we only execute a short<br />

sequence of method calls (perhaps just one) and check a single result.<br />

It is possible to code more realistic runs in unit tests, as we attempted in Section<br />

2.8, but this requires a great deal of effort. Unit test tools only automate test<br />

execution and logging test results; they still require the tester to code every run and<br />

each assertion. Some unit testing guides recommend writing as much or more test<br />

code as implementation code. 5 Our barely realistic unit test (Figure 2.10) is almost<br />

as long as the main methods in our applications (Figures 2.7 and 2.8). It is still too<br />

short; it did not detect the defect.<br />

<strong>We</strong> need more automation to generate and check realistic runs for testing. Simply<br />

calling methods at random would not work; we need meaningful sequences of<br />

method calls.<br />

2.12 <strong>Model</strong>-based testing reveals the defect<br />

Our methods automate test generation and checking, in addition to test execution<br />

and logging. The tester must describe the ordering constraints on methods and the<br />

intended results of methods by writing a model program. Our technology can then<br />

use the model program to automatically generate and check realistic runs of any<br />

desired length. Moreover, our methods can handle nondeterminism, so we can run<br />

more realistic tests where we only control one end of the client/server pair.<br />

<strong>We</strong> develop a model program for analyzing and testing this system in Chapter 5.<br />

<strong>We</strong> automatically generate tests from this model program in Chapter 8. Hereisa<br />

test run that reveals the defect:<br />

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

"Action ’ClientReceive_Finish(double(\"99\"))’ not enabled in the model",<br />

Unexpected return value of finish action, expected:<br />

ClientReceive_Finish(double "99.9"))<br />

Trace(<br />

Test(0),<br />

ServerSocket(),<br />

ServerBind(),<br />

ServerListen(),<br />

5 For example, see Rainsberger (2005, p. 79).<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!