State-Based Testing Part A Modeling states Generating test cases - - PowerPoint PPT Presentation

state based testing part a modeling states
SMART_READER_LITE
LIVE PREVIEW

State-Based Testing Part A Modeling states Generating test cases - - PowerPoint PPT Presentation

State-Based Testing Part A Modeling states Generating test cases for complex behaviour Reference: Robert V. Binder Testing Object-Oriented Systems: Models, Patterns, and Tools Addison-Wesley, 2000, Chapter 7 Motivation We are interested


slide-1
SLIDE 1

State-Based Testing Part A – Modeling states

Generating test cases for complex behaviour

Reference: Robert V. Binder Testing Object-Oriented Systems: Models, Patterns, and Tools Addison-Wesley, 2000, Chapter 7

slide-2
SLIDE 2

SM–2

Motivation

 We are interested in testing the behaviour of many different

types of systems, including event-driven software systems

 Interaction with GUI systems can follow a large number of

paths

 State machines can model event-driven behaviour  If we can express the system under test as a state machine,

we can generate test cases for its behaviour

slide-3
SLIDE 3

SM–3

OO Systems

 State-based testing is well suited to OO Systems  Behaviour responsibility is distributed over

 Classes, clusters, subsystem or system

 Behaviour bugs are due to complex and implicit structure

slide-4
SLIDE 4

SM–4

State machine

 What is a state machine?

 Informal definition

slide-5
SLIDE 5

SM–5

A state machine is …

 A system whose output is determined by both current state

and past input

 Previous inputs are represented in the current state  State-based behaviour

 Identical inputs are not always accepted

 Depends upon the state

 When accepted, they may produce different outputs

 Depends upon the state

slide-6
SLIDE 6

SM–6

Building blocks of a state machine

 What are the building blocks of a state machine?

slide-7
SLIDE 7

SM–7

Building blocks of a state machine – 2

 State

 An abstraction that summarizes past inputs, and

determines behaviour on subsequent inputs

 Transition

 An allowable two-state sequence. Caused by an event

 Event

 An input or a time interval

 Action

 The output that follows an event

slide-8
SLIDE 8

SM–8

State machine behaviour

 Describe the behaviour of a state machine?

slide-9
SLIDE 9

SM–9

State machine behaviour – 2

1. Begin in the initial state 2. Wait for an event 3. An event comes in

  • 1. If not accepted in the current state, ignore
  • 2. If accepted, a transition fires, output is produced (if

any), the resultant state of the transition becomes the current state 4. Repeat from step 2 unless the current state is a final state

slide-10
SLIDE 10

SM–10

State machine behaviour

 What are the properties of a state machine?

slide-11
SLIDE 11

SM–11

State machine properties

 How events are generated is not part of the model  Transitions fire one at a time  The machine can be in only one state at a time  The current state cannot change except by a defined

transition

 States, events, transitions, actions cannot be added during

execution

slide-12
SLIDE 12

SM–12

State machine properties – 2

 Algorithms for output creation are not part of the model  The firing of a transition does not consume any amount of

time

 An event is instantaneous

 It has no beginning or ending  Beginnings and endings imply duration

The challenge How to model the behaviour of a given system using a state machine.

slide-13
SLIDE 13

SM–13

State transition diagram

 What is a state transition diagram?

slide-14
SLIDE 14

SM–14

State transition diagram – example

slide-15
SLIDE 15

SM–15

Complete & incomplete specifications

 What are complete and incomplete state machine

specifications?

slide-16
SLIDE 16

SM–16

Complete & incomplete specifications – 2

 Complete specifications

 A transition for every event-state pair

 Incomplete specifications

 The norm for modeling

 For design too cumbersome to completely specify,

as only a small subset is of interest

 Cannot ignore unspecified event-state pairs for testing

 Why?

slide-17
SLIDE 17

SM–17

Equivalent states

 What are equivalent states?  What problem exists with equivalent states?

slide-18
SLIDE 18

SM–18

Equivalent states

 Any two states are equivalent

 If all possible event sequences applied to these states

result in identical behaviour

 By looking at the output cannot determine from which

state machine was started

 Can extend to any pair of states

 Minimal machine has no equivalent states

slide-19
SLIDE 19

SM–19

Equivalent states

 What problem exists with equivalent states?

slide-20
SLIDE 20

SM–20

Equivalent states

 A model with equivalent states is redundant

 Probably incorrect  Probably incomplete

slide-21
SLIDE 21

SM–21

Reachability

 What is reachability?

slide-22
SLIDE 22

SM–22

Reachability – 2

 State Sf is reachable from state St

 If there is a legal event sequence that moves the

machine from Sf to St

 Just stating a state is reachable implies reachable

from the initial state

slide-23
SLIDE 23

SM–23

Reachability problems

 Using the notion of reachability, what problems does it

show?

slide-24
SLIDE 24

SM–24

Reachability problems – 2

 Dead state

 Cannot leave

 Cannot reach a final state

 Dead loop

 Cannot leave

 Cannot reach a final state

 Magic state

 Cannot enter – no input transitions  Can go to other states

 Extra initial state

slide-25
SLIDE 25

SM–25

Guarded transitions

 What is a guarded transition?

slide-26
SLIDE 26

SM–26

Guarded transitions – 2

 The stack example state machine is ambiguous

 There are two possible reactions to push and pop in

the Loaded state

 Guards can be added to transitions  A guard is a predicate associated with the event  A guarded transition cannot fire unless the guard predicate

evaluates to true

slide-27
SLIDE 27

SM–27

Guarded transitions – example

slide-28
SLIDE 28

SM–28

Limitations of the basic model

 Limited scalability

 Even with the best tools available, diagrams with 20

states or more are unreadable

 Concurrency cannot be modeled

 Different processes can be modeled with different

state machines, but the interactions between them cannot

 Not specific enough for Object-Oriented systems

slide-29
SLIDE 29

SM–29

Statechart – Scalability – traffic light example

slide-30
SLIDE 30

SM–30

Traffic light with superstates – all states view

Superstates Common to all inner states Initial state

slide-31
SLIDE 31

SM–31

Traffic light – top level view

slide-32
SLIDE 32

SM–32

Traffic light – level 1 view

slide-33
SLIDE 33

SM–33

Traffic light – level 2 view

slide-34
SLIDE 34

SM–34

Concurrent statechart

slide-35
SLIDE 35

SM–35

Statechart advantages

 Easier to read  Suited for object oriented systems (UML uses statecharts)  Hierarchical structure helps with state explosion  They can be used to model concurrent processes as well

slide-36
SLIDE 36

SM–36

Statechart problems

 Can vary in their details and implementation with different

case systems

 Need to be very careful when testing

slide-37
SLIDE 37

SM–37

State model

 Must support automatic test generation  The following criteria must be met

 Complete and accurate reflection of the

implementation to be tested

 Allows for abstraction of detail  Preserves detail that is essential for revealing faults  Represents all events and actions  Defines state so that the checking of resultant state

can be automated

slide-38
SLIDE 38

SM–38

What is a state?

 We need an executable definition that can be evaluated

automatically

 An object with two Boolean fields has 4 possible states?

 This would lead to trillions of states for typical classes

slide-39
SLIDE 39

SM–39

Trillions of states

slide-40
SLIDE 40

SM–40

What is a state? – 2

 How can we address the problem?

slide-41
SLIDE 41

SM–41

What is a state? – 3

 A set of variable value combinations that share some property

  • f interest

 Can be coded as a Boolean expression

slide-42
SLIDE 42

SM–42

An example

 Consider the following class  The cross-product of all values is a primitive view of the state

space

 Yields too many states

 What abstraction gives fewer states?  How is the abstraction represented?

Class Account { AccountNumber number; Money balance; Date lastUpdate; … }

slide-43
SLIDE 43

SM–43

Three abstract states

Shaded volumes

slide-44
SLIDE 44

SM–44

State invariants

 A valid state can be expressed with a state invariant

 A Boolean expression that can be checked

 A state invariant defines a subset of the values allowed by the

class invariant

ensure a or b

 In Eiffel this defines two possible states

slide-45
SLIDE 45

SM–45

Transitions

 A transition is a unique combination of

 Two state invariants

 One for the accepting  One for the resultant state  Both may be the same

 An associated event  An optional guard expression  Optional action or actions

slide-46
SLIDE 46

SM–46

Transition events

 A message sent to the class under test  A response received from a supplier of the class under test  An interrupt or similar external control action that must be

accepted

slide-47
SLIDE 47

SM–47

Transition actions & guards

 A guard

 Predicate associated with an event  No side effects

 An action

 The side effect that occurs

slide-48
SLIDE 48

SM–48

Alpha states

 The initial state of an object is the state right after it is

constructed

 However, a class may have multiple constructors that leave

the object in different states

 To avoid modeling problems we define that an object is in

the α state just before construction

 α transitions go from α state to a constructor state

slide-49
SLIDE 49

SM–49

Omega states

 Similarly with ω and destruction

 Not necessary to model ω for languages that have

garbage collection

 ω transitions go from a destructor state to the ω

state