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.

58 <strong>Model</strong> Programs<br />

system comprising several programs, or a distributed system that includes several<br />

computers connected by a network. A model program can also represent the environment<br />

where the implementation runs, including messages in transit between<br />

networked computers, or events originating in attached hardware.<br />

Actions are the units of behavior. In many kinds of systems, including computer<br />

systems, behaviors are made up of discrete, discontinuous steps. Each step is an<br />

action. An action can be composed of several smaller activities, but an action is<br />

atomic: once it begins, it runs to completion, without being interrupted or preempted<br />

by another action. For each kind of action in the implementation, there is a method<br />

in the model program. When the model program runs, each method call represents<br />

an action in the implementation. 1<br />

State is the information stored in a program or system at one point in time.<br />

The concept of state captures our intuition of a “situation” or “state of affairs”: the<br />

important properties of a system at one moment. The state of the implementation is<br />

represented by variables of the model program. Each particular assignment of values<br />

to variables in the model program represents a particular state (a situation) of the<br />

implementation. The variables in the model program that represent implementation<br />

state are called state variables (to distinguish them from the model program’s<br />

local variables, parameters, etc.). State variables in the model program need not<br />

correspond exactly to program variables in the implementation; they might represent<br />

information that is not stored in implementation variables (messages in transit, for<br />

example).<br />

Every program or system starts up in an initial state. The initial state is usually<br />

an empty or idle state. Behavior continues until the system reaches an accepting<br />

state. An accepting state is usually a state where the program’s goals have been<br />

achieved, where some unit of work has been completed. The system may stop in<br />

an accepting state; alternatively, it may continue, starting new work. A sequence of<br />

actions beginning in the initial state and ending in an accepting state is called a run<br />

or a trace. A run must not end in a state that is not an accepting state (if the model<br />

program does not identify any accepting states, a run may end in any state). The<br />

runs of a model program are sequences of method calls (and returns).<br />

The behavior of a program or system is the complete collection of all the runs<br />

that it can execute. A contract model program is a specification that describes<br />

all of the allowed behavior of its implementation: it describes everything that its<br />

implementation must do, might do, and must not do. Every run that a contract<br />

model program can execute represents a run that its implementation must be able to<br />

execute. A contract model program cannot execute any run that its implementation is<br />

forbidden to execute. A contract model program often has a large collection of runs;<br />

1 This is a simplification; the relation between actions in the implementation and methods in the<br />

model program is not always one-to-one. Chapters to come and Appendix A tell the whole story.<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!