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 Finite <strong>Model</strong>s 93<br />

actions. <strong>Model</strong>s are made simple by slicing and abstraction, and are often finitized<br />

before analysis. <strong>Model</strong>s are written by coding action methods with enabling conditions.<br />

But other systems often use different vocabulary for the concepts. For example,<br />

an action method might be called an update rule, an enabling condition is a guard or<br />

precondition, the combination of an action method with its enabling conditions is a<br />

guarded update rule, and a model program written in this style is a guarded update<br />

program. Other systems also use different programming languages (or different<br />

coding conventions in the same language) for writing the model programs.<br />

5.9 Exercises<br />

1. Write a simple implementation of the newsreader model program of Section 5.4.<br />

Your implementation need not provide any user interface, just provide an API<br />

with a method for each action. Describe how you implemented the enabling<br />

conditions, and explain your rationale.<br />

2. Write and execute unit tests for your implementation that execute the runs<br />

simulated in Section 5.5. How does your implementation handle the second run,<br />

where the last action is not enabled?<br />

3. Create a version of your newsreader implementation that contains a defect in<br />

(your implementation of) an enabling condition. Write a unit test that exposes<br />

the defect.<br />

4. Create a version of your newsreader implementation that contains a defect in<br />

(your implementation of) an action method. Write a unit test that exposes the<br />

defect.<br />

5. Revise the reactive system model program of Section 5.7 to correct the design<br />

errors. This version should have no unsafe states and no dead states. In other<br />

words, model the implementation you wrote in Chapter 3, Exercise 3. Hint: use<br />

the design rules given in Section 3.6.<br />

Save the programs you wrote for these exercises to use in exercises in chapters<br />

to come.<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!