lecture 5

47
Lecture 5 Model-Based Testing

Upload: laurie

Post on 24-Feb-2016

52 views

Category:

Documents


0 download

DESCRIPTION

Lecture 5. Model-Based Testing. What is model-based testing?. Model-based testing can be conducted as part of model-based development Model-based development = describing software using accurate modeling languages e.g. UML - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture  5

Lecture 5

Model-Based Testing

Page 2: Lecture  5

What is model-based testing?

• Model-based testing can be conducted as part of model-based development

• Model-based development = describing software using accurate modeling languages e.g. UML

• If a model describes the software we can use this model to construct test cases.

• C.f. reference models in lecture 4.

Page 3: Lecture  5

Modeling Maturity Level

• Level 0: No specification: software specifications are only in the heads of developers

• Level 1: Textual: The software specifications are written down in informal natural language documents

• Level 2: Models with text: a set of models (diagrams or text with well defined meanings). Natural language is used to motivate, explain and detail models. Transition from model to code is manual. Model synching with code is difficult.

Page 4: Lecture  5

• Level 4, Precise models: code can be generated from models, and modified for special requirements. Model has a precise meaning independent of natural language. Natural language still used.

• Level 5, Models only: model is like a high-level programming language. Model-to-code generation automatic (compiler). Generated code used without changes.

Page 5: Lecture  5

UML Statecharts

• A UML statechart, is an object-based variant of Harel’s statechart language.

• Statecharts overcome limitations of finite state machines, without losing benefits.

• Combine aspects of Moore and Mealy machines• New concepts: – Hierarchically nested states– Orthogonal regions– Extended actions– History

Page 6: Lecture  5

Classical automata

• Moore-automata:Y = (Z); Z+ = (X, Z)

• Mealy-automataY = (X, Z); Z+ = (X, Z)

Internal state Zinput X output Y

Next state Z+ computed by function Output computed by function

Z0 Z1

Z2Z3

e=1

e=1

e=1

e=1

0 1

23

clockMoore- + Mealy automata=finite state machines (FSMs)

Page 7: Lecture  5

UML 2.4

• Two kinds of state machines.• Behavioral state machines are used to model the

behavior of individual entities (e.g., class instances)

• Protocol state machines are used to express usage protocols and can be used to specify the legal usage scenarios of classifiers, interfaces, and ports.

• Behavioral state machine is subclassed by protocol state machine.

Page 8: Lecture  5

Behavioral Machines

• Behavior is modeled as traversal of a graph of state nodes connected by transitions, tiggered by a series of events.

Page 9: Lecture  5

Behavioural States

• Model a a situation during which some (usually implicit) invariant condition holds. The invariant may represent a static situation such as an object waiting for some external event to occur.

• Can also model dynamic conditions such as the process of performing some behavior

Page 10: Lecture  5

Simple States

• A simple state is a state that does not have substates

• Rectangle with rounded corners and the state name inside the rectangle.

Page 11: Lecture  5

• Simple state may have compartments. • Name compartment holds the (optional) name of the

state, as a string. States without names are called anonymous states and are all considered distinct (different) states.

• Internal activities compartment holds a list of internal actions or state activities performed while the element is in the state. Activity label identifies the circumstances under which the behavior specified by the activity expression will be invoked. The behavior expression may use any attributes and association ends that are in the scope of the owning entity. For list items where the expression is empty, the backslash separator is optional.

Page 12: Lecture  5

• Several labels are reserved for special purposes and cannot be used as event names.

• entry (behavior performed upon entry to the state)

• do (ongoing behavior, performed as long as the element is in the state)

• exit (behavior performed upon exit from the state)

Page 13: Lecture  5

• E.g.

• has name and activity compartments

Page 14: Lecture  5

Composite State

• A state that has substates (nested states). Substates can be sequential (disjoint, “or”) or concurrent (orthogonal, “and”) only.

• UML 2.4 defines composite state as the state which contains one ore more regions.

• Simple composite state contains just one region. 1 sequential

state with2 substates

Page 15: Lecture  5

• Orthogonal composite state has more than one regions. Each region has a set of mutually exclusive disjoint subvertices and a set of transitions.

• Any state enclosed within a region of a composite state is called a substate of that composite state.

• It is direct when not contained by any other state; otherwise, it is indirect.

• Each region of a composite state may have an initial pseudostate and a final state.

Page 16: Lecture  5

• Composite state may have compartments. The compartments of the state are:

• name • internal activities • internal transitions • decomposition

• Above indicates a complex decomposition found in another diagram.

Page 17: Lecture  5

Pseudostates

• Initial Junction• Terminate Shallow history• EntryDeep history• Exit• Choice• Join• Fork

Page 18: Lecture  5

• An initial pseudostate represents a default vertex that is the source for a single transition to the default state of a composite state.

• At most one• Behavior, but no trigger or guard

Page 19: Lecture  5

• Terminate pseudostate means the execution of this state machine by means of its context object is terminated.

• Doesn’t exit states or perform exit actions.• equivalent to invoking a DestroyObjectAction.

Page 20: Lecture  5

• Entry point pseudostate is an entry point of a state machine or composite state.

• Has at most a single transition to a vertex within the same region

Page 21: Lecture  5

• Exit point pseudostate is an exit point of a state machine or composite state.

• Entering an exit point within any region of the composite state or state machine referenced by a submachine state implies

• (1) the exit of this composite state or submachine state and,

• (2) the triggering of the transition that has this exit point as source in the state machine enclosing the submachine or composite state.

Page 22: Lecture  5

Exit point

Page 23: Lecture  5

• Choice pseudostate realizes a dynamic conditional branch.

• Evaluates the guards of the triggers of its outgoing transitions

• Selects only one outgoing transition. • The decision on which path to take may be a

function of the results of prior actions performed in the same run-to-completion step.

Page 24: Lecture  5

Choice pseudostate (2 styles)

• If more than one guard is true, non-determinism arises.

• If no guard is true model is ill-formed.• Fix with “else” guard

Page 25: Lecture  5

• Fork pseudostate vertices split an incoming transition into two or more, terminating on orthogonal target vertices (i.e., vertices in different regions of a composite state).

• The segments outgoing from a fork vertex must not have guards or triggers.

Page 26: Lecture  5

• Join pseudostate merges several transitions originating from source vertices in different orthogonal regions.

• The transitions entering a join vertex cannot have guards or triggers.

Page 27: Lecture  5

• Junction pseudostate is used to chain together multiple transitions.

• Used to construct compound transition paths between states.

• E.g. converge multiple incoming transitions into a single outgoing transition (merge).

• E.g. split an incoming transition into multiple outgoing transitions with different guard conditions. This realizes a static conditional branch.

• Represented by a small black circle.

Page 28: Lecture  5

• Final state is a special kind of pseudostate signifying that the enclosing region is completed.

• If enclosing region is directly contained in a state machine and all other regions in the state machine also are completed, then it means entire state machine is completed.

Page 29: Lecture  5

History pseudostate

•For input m, S enters the state it was in before S was left (can be A, B, C, D, or E). If S is entered for the very first time, the default mechanism applies.•History and default mechanisms can be used hierarchically.

Page 30: Lecture  5

Behavioral Transitions

• A transition is a directed relationship between a source and target vertex.

• may be part of a compound transition• UML 2.4• behavioral-transition ::= [ triggers ] [ '[' guard-

constraint ']' ] [ '/' behavior-expression ] triggers ::= trigger [ ',' trigger ]*

Page 31: Lecture  5

Trigger list

• (optional) trigger list specifies events that may induce transition

• Event satisfies trigger if it matches event of trigger

• Satisfaction is necessary but not sufficient to take transition (more than one match!)

Page 32: Lecture  5

Guard constraints

• The guard-constraint is a Boolean expression written in terms of parameters of the triggering event. May also involve

• tests of orthogonal states of the current state machine,

• explicitly designated states of some reachable object (for example, "in Active State")

Page 33: Lecture  5

Guard evaluation

• In simple transition, guard is evaluated before transition is triggered.

• In compound transitions (multiple guards), all guards are evaluated before transition is triggered, unless there are choice points along one or more of the paths.

• The order in which guards are evaluated is not defined. Guards should not include expressions causing side effects

Page 34: Lecture  5

Behavior expression

• behavior-expression is executed when the transition fires.

• May be written in terms of operations, attributes, and links of the context object and the parameters of triggering event, or any other features visible in its scope.

• behavior expression may be an action sequence

Page 35: Lecture  5

Transition Example

• left-mouse-down(coordinates) [coordinates in active_window] / link:=select-link(coordinates);link.follow()

• When left-mouse-down event happens (trigger) and click coordinates are in active_window (guard), link will be selected and followed (behavior-expression), and transition fired.

Page 36: Lecture  5

Leaving and entering states

• Transitions originating from composite states are called high-level transitions.

• If triggered, they result in exiting all substates of the composite state executing their exit activities starting with the innermost states.

• A compound transition represents a "semantically complete" path made of one or more transitions, originating from a set of states (as opposed to pseudo-state) and targeting a set of states.

Page 37: Lecture  5

Leaving and entering states (cont)

• An internal transition executes without exiting or re-entering the state in which it is defined. This is true even if the state machine is in a nested state within this state.

Page 38: Lecture  5

Water Phase Diagram

Page 39: Lecture  5
Page 40: Lecture  5
Page 41: Lecture  5

Execution order

• UML specifies that taking a state transition executes the following actions in the following sequence

1. Evaluate the guard condition associated with the transition and perform the following steps only if the guard evaluates to TRUE.

2. Exit the source state configuration.3. Execute the actions associated with the transition.4. Enter the target state configuration.

Page 42: Lecture  5

Least Common Ancestor

• In 2 is not obvious what states are exited• exit all nested states from the current active

state (direct or indirect substates of the main source state) up to, but not including, the least common ancestor (LCA)

• LCA is the lowest state that is a superstate of both the source and the target states

Page 43: Lecture  5

Taking T1 causes the evaluation of guard g();Exit of s11, s1, Action sequence a(); b(); t(); c(); d(); and e(); Entry of s2, s21 (assuming guard g() evaluates to TRUE)

Page 44: Lecture  5
Page 45: Lecture  5
Page 46: Lecture  5
Page 47: Lecture  5

Exercise: microwave oven

• We wish to model a basic oven with a door and a « start » button

• Once a meal has been put in the oven, the user pushes the « start » button. Once pushed, the meal is heated for 30 seconds. Then, the oven stops and plays a bell sound

• Alternatively, the user may open the door while the oven is heating. In that case, the heating process stops and the 30s delay is set to 0