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.

64 <strong>Model</strong> Programs<br />

5.3.6 Select the state variables<br />

Now we can select the state variables. This is a bit more difficult because we can’t<br />

simply observe them. <strong>We</strong> must infer them from the behavior; in particular, from the<br />

sample traces we wrote. (In this example we don’t have access to any source code<br />

or documentation.)<br />

The state variables in a model program serve just three purposes: first, to determine<br />

what runs are possible by selecting the actions that are enabled in each state; second,<br />

to determine the data that appear during runs by storing the arguments and return<br />

values of the actions; and third, to support safety and liveness analyses by describing<br />

the safe states and accepting states.<br />

<strong>We</strong> select these state variables: The page variable indicates which kind of page is<br />

displayed, Topics or Messages. The style variable indicates the appearance of the<br />

entries on the topics page, WithText or TitlesOnly. The sort variable indicates the<br />

sort order of the topics page when titles only are shown: ByFirst or ByMostRecent.<br />

Stored information that determines the sequencing of actions is called control<br />

state; other stored information is data state. All of our state variables store control<br />

state. For this example we chose a high level of data abstraction where we ignore<br />

the page contents (the titles and messages). Our actions have no arguments or return<br />

values. Therefore this model program has no data state, apart from what is already<br />

stored in the control state.<br />

By limiting the state variables to the control state, we ensure that the model<br />

program is finite. In fact, it is quite small. The state space of a program is the set of<br />

all states that it can reach. Here we have only three state variables, each with only<br />

two values, so at most there can only be 2 × 2 × 2 or eight states in this program’s<br />

state space. The implementation’s state space is “infinite,” because it includes the<br />

topics and messages, which include strings, a data type that has an “infinite” number<br />

of values. Our choice of state variables has finitized the model program. This is an<br />

example of data abstraction.<br />

5.4 Coding the model program<br />

Now that we have selected the actions and state variables, we can code the model<br />

program (Figures 5.4 and 5.5). The modeling library and tools support programs<br />

that are coded in a few particular styles. In order to work with the tools, a model<br />

program must be coded in one of these styles. In this chapter we introduce the style<br />

we use for most of the examples in this book. A complete reference for writing<br />

model programs in this style appears in Appendix A. Other styles are introduced in<br />

Chapter 7, Section 7.3.2.<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!