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 95<br />

Table 6.1. Newsreader scenario FSM: state transition table<br />

Current state Action (invocation) Next state<br />

Topics, WithText, ShowTitles() Topics, TitlesOnly,<br />

ByMostRecent ByMostRecent<br />

Topics, TitlesOnly, SortByFirst() Topics, TitlesOnly,<br />

ByMostRecent ByFirst<br />

Topics, TitlesOnly, SortByMostRecent() Topics, TitlesOnly,<br />

ByFirst ByMostRecent<br />

Topics, TitlesOnly, ShowText() Topics, WithText,<br />

ByMostRecent ByMostRecent<br />

To describe a run of a model program, we only need to show the actions (the<br />

action method calls). More thorough analyses must use the states as well. When we<br />

consider states and actions together, we find that an action often causes a change of<br />

state: a state transition. FSMs are built up from state transitions, not just actions.<br />

To completely describe each state transition, we must identify the current state before<br />

the transition, the next state after the transition (also called the target state), and<br />

the action. To completely describe each action, we must show the entire invocation<br />

(the action name and all of its arguments) and the return value (if there is one).<br />

An FSM is simply a finite collection of state transitions described in this way,<br />

along with an identification of the initial state where every run begins, and optional<br />

accepting states where runs are allowed to end (if no accepting states are identified,<br />

runs may end in any state). A run is a sequence of state transitions, so any run can<br />

define an FSM. But a run is an ordered collection, while an FSM is unordered. It<br />

is not necessary to order the FSM because each transition identifies its current and<br />

next states.<br />

An FSM can be represented by a state transition table or a state transition diagram.<br />

Table 6.1 shows the state transition table that represents the FSM for the successful<br />

simulation run of Chapter 5, Section 5.5:<br />

ShowTitles(); SortByFirst(); SortByMostRecent(); ShowText();<br />

<strong>We</strong> simply enter a row in the table for each transition in the run, filling in the states<br />

and the method calls from the output of the run. An FSM is an unordered collection,<br />

so we can put the rows in any order we like. In our tables, we always put the<br />

transitions that begin in the initial state in a separate section at the top of the table,<br />

separated by a double line. After that, we put all transitions that begin in the same<br />

state together in the table. These are just conventions that make the table easy to<br />

read; any other order would express the same FSM. Often, rows in our tables appear<br />

in a different order than that in which the transitions occur in our example runs.<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!