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.

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

}<br />

}<br />

}<br />

}<br />

// ... continued<br />

case("ClientSocket"):<br />

c.Socket(); return null;<br />

case("ClientConnect"):<br />

c.Connect(host,port); return null;<br />

case("ClientSend"):<br />

c.Send("T"); return null;<br />

case("ClientReceive_Start"):<br />

// c.Receive returns a double, not a string<br />

return Action.Create("ClientReceive_Finish", c.Receive());<br />

case("ClientClose"):<br />

c.Close(); return null;<br />

default: throw new Exception("Unexpected action " + action);<br />

public void Reset()<br />

{<br />

s = new Server();<br />

c = new Client();<br />

}<br />

// Factory method<br />

public static IStepper Create()<br />

{<br />

return new Stepper();<br />

}<br />

Figure 8.5. Client/server: test harness (stepper) (2).<br />

The DoAction method is the core of the test harness. It invokes the implementation’s<br />

controllable actions, monitors the implemenation’s observable actions, collects<br />

the output from the implementation, and checks the implementation against<br />

the model.<br />

To invoke each controllable action, the test runner passes DoAction a term that<br />

represents the action. There is a case in DoAction for each action symbol. The code<br />

in the case branch invokes the corresponding method in the implementation. In the<br />

simple case where the action has no outputs, DoAction returns null.<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!