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.

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

the model program, which appears in parentheses in the term. The pair of actions is<br />

called a split action. Any action method that has outputs (a return value or C# out or<br />

byref parameters) must be modeled as a split action. You do not have to code both<br />

actions in your model program; the tools automatically create split actions from<br />

every action method with outputs (use the mpv option combineActions- to display<br />

both actions in each pair).<br />

It is necessary to model the two actions separately because the implementation<br />

might not execute the finish action. The start action is controllable; the test harness<br />

can always cause the implementation to execute the method call. But the finish<br />

action is observable; the test harness can only wait for the method return. If the<br />

implementation crashes or hangs, the method will not return and the finish action<br />

will not occur. The test runner indicates that these are failures.<br />

Actions (with no outputs) that are not split actions are called atomic actions.<br />

Actions are not exactly the same as method calls, and (e.g., with split actions) there<br />

is not always a one-to-one relation between method calls and actions. Therefore, we<br />

must distinguish between method names and action symbols, the names of actions.<br />

The default behavior of the library and tools is to automatically derive the action<br />

symbols from method names, but you can also assign your own action symbols in<br />

the action attributes (Appendix A). The entire collection of action symbols used by<br />

a model program is called its action vocabulary or just its vocabulary.<br />

8.3 Test harness<br />

A test harness is code that enables a test runner to execute an implementation. You<br />

must write a test harness for each implementation. Figures 8.4 and 8.5 show the<br />

test harness that connects the client/server implentation to the ct tool. The implementation<br />

appears in Chapter 2, Figures 2.3–2.5.<br />

You can write the harness to accommodate differences between the model and<br />

the implementation. The harness in Figures 8.4 and 8.5 drives an implementation<br />

where sockets are objects, but in the model they are static variables. Although the<br />

library and tools use .NET, you can write a harness for an implementation that does<br />

not use .NET.<br />

Write the test harness in the same namespace as the implementation. The test<br />

harness implements the modeling library’s IStepper interface, so we often call a<br />

test harness a stepper; it “steps” the implementation through the actions of each test<br />

case. To implement the IStepper interface you must write two methods, Reset and<br />

DoAction. The stepper must also provide a factory method that returns the stepper<br />

object.<br />

The Reset method executes after each test case to reset the implementation to its<br />

initial state.<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!