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.

ShowText()<br />

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

6<br />

SortByFirst()<br />

4<br />

ShowTitles()<br />

SelectMessages() SelectTopics()<br />

7<br />

ShowTitles()<br />

2<br />

SortByMostRecent()<br />

SelectMessages()<br />

5<br />

0<br />

ShowText()<br />

3<br />

SelectMessages() SelectTopics()<br />

SelectMessages() SelectTopics()<br />

SelectTopics()<br />

Figure 6.4. Newsreader true FSM: state transition diagram drawn by mpv tool.<br />

It can be helpful to view the graph produced by exploration even when you do<br />

not have a precise question in mind, because it might reveal that the model program<br />

does not behave as you intend. For example, you may see many more or many fewer<br />

states and transitions than you expected, or you may see dead ends or cycles you<br />

did not expect.<br />

<strong>We</strong> recommend that you explore and view your model program as you develop<br />

it, so you can check frequently that it behaves as you intend. There is no need to<br />

finish the model program first; you can begin exploring as soon as you have coded<br />

a few actions.<br />

6.2.3 Interactive exploration and simulation<br />

The mpv tool can also explore interactively, executing and displaying a few transitions<br />

at a time, under the user’s control. This provides a more convenient way to simulate<br />

particular runs than coding and executing main methods or unit tests, as we did in<br />

Chapter 5, Section 5.5<br />

Figures 6.5 and 6.6 show the interactive exploration of the first run we tested in<br />

Chapter 5. At first, only the initial state appears. At our command, mpv shows all the<br />

actions enabled in the initial state. <strong>We</strong> select ShowTitles by selecting its next state<br />

(Figure 6.5). Then we command mpv to show all the transitions enabled in that state,<br />

more free ebooks download links at:<br />

http://www.ebook-x.com<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!