1 / 47

Lecture 5

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

laurie
Télécharger la présentation

Lecture 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 5 Model-Based Testing

  2. 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.

  3. 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.

  4. 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.

  5. UML Statecharts • AUML statechart, is an object-based variant of Harel’sstatechart 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

  6. Classical automata input X Internal state Z output Y clock Moore- + Mealy automata=finite state machines (FSMs) Next state Z+ computed by function Output computed by function  e=1 Z0 Z1 • Moore-automata:Y =  (Z); Z+ =  (X, Z) • Mealy-automataY =  (X, Z); Z+ =  (X, Z) 0 1 e=1 e=1 Z3 Z2 2 3 e=1

  7. 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 subclassedby protocol state machine.

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

  9. 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

  10. Simple States • A simple state is a state that does not have substates • Rectangle with rounded corners and the state name inside the rectangle.

  11. Simple state may have compartments. • Name compartmentholds the (optional) name of the state, as a string. States without names are called anonymous statesand are all considered distinct (different) states. • Internal activities compartmentholds 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.

  12. 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)

  13. E.g. • has name and activity compartments

  14. Composite State • A state that has substates (nested states). Substatescan 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 statecontains just one region. 1 sequential state with 2 substates

  15. Orthogonal composite statehas 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 pseudostateand a final state.

  16. 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.

  17. Pseudostates • Initial Junction • Terminate Shallow history • Entry Deep history • Exit • Choice • Join • Fork

  18. An initial pseudostaterepresents a default vertex that is the source for a single transition to the default stateof a composite state. • At most one • Behavior, but no trigger or guard

  19. Terminate pseudostatemeans 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.

  20. Entry point pseudostateis an entry point of a state machine or composite state. • Has at most a single transition to a vertex within the same region

  21. Exit point pseudostateis 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.

  22. Exit point

  23. Choice pseudostaterealizes 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.

  24. 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

  25. Fork pseudostatevertices 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.

  26. Join pseudostatemerges several transitions originating from source vertices in different orthogonal regions. • The transitions entering a join vertex cannot have guards or triggers.

  27. Junction pseudostateis 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.

  28. Final stateis a special kind of pseudostatesignifying 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.

  29. 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.

  30. 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 ]*

  31. 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!)

  32. Guard constraints • The guard-constraintis 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")

  33. 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

  34. Behavior expression • behavior-expressionis executed when the transition fires. • May be written in terms of operations, attributes, and links of the context objectand the parameters of triggering event, or any other features visible in its scope. • behavior expression may be an action sequence

  35. Transition Example • left-mouse-down(coordinates) [coordinates inactive_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.

  36. Leaving and entering states • Transitions originating from composite statesare 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 transitionrepresents 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.

  37. 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.

  38. Water Phase Diagram

  39. Execution order • UML specifies that taking a state transition executes the following actions in the following sequence • Evaluate the guard condition associated with the transition and perform the following steps only if the guard evaluates to TRUE. • Exit the source state configuration. • Execute the actions associated with the transition. • Enter the target state configuration.

  40. Least Common Ancestor • In 2 is not obvious what states are exited • exit all nested states from the current active state (direct or indirect substatesof the main source state) up to, but not including, the least common ancestor(LCA) • LCA is the lowest state that is a superstateof both the source and the target states

  41. Taking T1causes 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)

  42. 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

More Related