State-Based Testing Part B Error Identification Generating test - - PowerPoint PPT Presentation

state based testing part b error identification
SMART_READER_LITE
LIVE PREVIEW

State-Based Testing Part B Error Identification Generating test - - PowerPoint PPT Presentation

State-Based Testing Part B Error Identification Generating test cases for complex behaviour Reference: Robert V. Binder Testing Object-Oriented Systems: Models, Patterns, and Tools Addison-Wesley, 2000, Chapter 7 Flattening the statechart


slide-1
SLIDE 1

State-Based Testing Part B – Error Identification 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

SEI–2

Flattening the statechart

 Statecharts are great for communication, reducing clutter etc.  They might hide subtle bugs

 e.g. entering a sub-state rather than a super-state

slide-3
SLIDE 3

SEI–3

Flattening the statechart – 2

 For testing we need to expand them to full transition diagrams

 Expansion makes implicit transitions explicit, so they are

not lost

 Expansion is a flat view – includes everything

 From inheritance in OO  From sub-states in statecharts

 An automatable process

slide-4
SLIDE 4

SEI–4

Concurrent statechart

slide-5
SLIDE 5

SEI–5

Concurrency Hides Problems

 Concurrency hides implicit state combinations

 Arise from implicit state combinations  Hides potential serious defects

 Explicit violations of implicit prohibitions should be tested

slide-6
SLIDE 6

SEI–6

Expanding the Example

¡

slide-7
SLIDE 7

SEI–7

Expanding the Example – 2

Events, guards and output for the automotive control FSM

slide-8
SLIDE 8

SEI–8

Unspecified Event/State Pairs

 State machine models will not include all events for all states  Implicit transitions may be

 Illegal  Ignored  Or a specification omission

slide-9
SLIDE 9

SEI–9

Unspecified Event/State Pairs – 2

 Accepted illegal events lead to bugs called sneak paths  For testing purposes, we cannot ignore implicit behaviour

 Develop a Response Matrix

slide-10
SLIDE 10

SEI–10

Example statechart

slide-11
SLIDE 11

SEI–11

Response matrix work with flattened model

F T

slide-12
SLIDE 12

SEI–12

Response matrix – notes

 For events that have guards

 Give decision table for all combinations  Have one row with don't care (DC)

 Event is unguarded  E.g. event 2 out of state B is unguarded but is guarded out of

state A, so out of state B decision table entries are excluded

 Also used for excluded entries

slide-13
SLIDE 13

SEI–13

Response matrix – notes – 2

 Excluded entries

 These are for impossible cases

 Out of state alpha (constructor) every event, except for

construction is impossible

 Cannot react to event before machine is created/started  Ctor is the creation/start event  No such event  There is no event 4 out of state A  Must handle illegal event  Do not care what the guards are

 Use DC line to specify illegal event response  Exclude specific decision table guard lines

slide-14
SLIDE 14

SEI–14

Possible responses to illegal events

slide-15
SLIDE 15

SEI–15

Designing responses to illegal events

 Abstract state should not change

 Concrete state may change due to exception handling

 Illegal event design question

 Handle with defensive programming

 Uncooperative (defensive) systems

 Handle with precondition contracts

 Cooperative systems

slide-16
SLIDE 16

SEI–16

Designing responses to illegal events – 2

 Possible responses

 Raise exception  Treat message as a no-op  Attempt error recovery  Invoke abnormal termination

 Tester needs to decide expected responses so actual

responses can be evaluated

slide-17
SLIDE 17

SEI–17

State model validation

 Before it is used to generate test cases a state model

must be

 Complete  Consistent  Correct

 Passes checklists

slide-18
SLIDE 18

SEI–18

Checklist questions

 What is a checklist?  Why do we use checklists?  What checklists would be useful for statecharts?

slide-19
SLIDE 19

SEI–19

Validation checklists

 We will look at five validation checklists

 Structure checklist  State name checklist  Guarded transition checklist  Robustness checklist  Well-formed subclass behaviour checklist

slide-20
SLIDE 20

SEI–20

Structure checklist question

 What would you look for to verify the structure of a

statechart is correct?

slide-21
SLIDE 21

SEI–21

Structure checklist

 There is an initial state with only outbound transitions  There is a final state with only inbound transitions

 If not, explicit reason is needed

 Except for the initial and final states, every state has at least

  • ne incoming and one outgoing transition
slide-22
SLIDE 22

SEI–22

Structure checklist – 2

 Every state is reachable from the initial state  The final state is reachable from all states  No equivalent states

slide-23
SLIDE 23

SEI–23

Structure checklist – 3

 Every defined event and every defined action appears in at

least one transition

 The events accepted in a particular state are

 Unique  Or differentiated by mutually exclusive guard

slide-24
SLIDE 24

SEI–24

Structure checklist – 4

 Complete specification

 For every state, every event is accepted or rejected

 Either explicitly or implicitly

slide-25
SLIDE 25

SEI–25

Name checklist question

 What would you look for in a name checklist?

slide-26
SLIDE 26

SEI–26

State name checklist

 Poor names are indications of

 Incomplete design  Or incorrect design

 Adjectives are best

 Past participles are OK

slide-27
SLIDE 27

SEI–27

State name checklist – 2

 Names must be meaningful in the context of the application  State names should be passive  If a state is not necessary, leave it out

 “Wait states” are often superfluous

slide-28
SLIDE 28

SEI–28

Guarded transition checklist question

 What would you look for to ensure the guards on

transitions are correct in a statechart?

slide-29
SLIDE 29

SEI–29

Guarded transition checklist

 Guard variables are visible  Each guard is mutually exclusive of all other guards  The evaluation of a guard does not cause side effects

slide-30
SLIDE 30

SEI–30

Guarded transition checklist – 2

 The entire range of truth values for a particular event is

covered

 All combinations of multi-conditions predicates

 Guards with three or more variables are modeled with a

decision table

slide-31
SLIDE 31

SEI–31

Robustness checklist question

 What would you look for in a robustness checklist for a

statechart?

slide-32
SLIDE 32

SEI–32

Robustness checklist

 There is an explicit specification for an error-handling or

exception-handling mechanism for implicitly rejected events

 Illegal events do not corrupt the machine

 Preserve the last good state  Reset to a valid state  Or self-destruct safely

slide-33
SLIDE 33

SEI–33

Robustness checklist – 2

 Actions have no side effects on the resultant state  For contract violations specify mechanism for

 Explicit exception  Error logging  Recovery

slide-34
SLIDE 34

SEI–34

Well-formed subclass behaviour checklist question

 What would you look for in a well-formed subclass

behaviour checklist for a statechart?

slide-35
SLIDE 35

SEI–35

Well-formed subclass behaviour checklist

 Does not remove any superclass states

 All transitions accepted in the superclass are accepted in

the subclass

 All guards on superclass transitions are

 The same for subclass transitions  Or weaker for subclass transitions

slide-36
SLIDE 36

SEI–36

Well-formed subclass behaviour checklist – 2

 Subclass does not weaken the state invariant of the

superclass

 Subclass may add an orthogonal state defined with respect to

its locally introduced instance variables

slide-37
SLIDE 37

SEI–37

Well-formed subclass behaviour checklist – 3

 All inherited actions are consistent with the subclass's

responsibilities

 Verify name-scope sensitive or dynamic binding of

intraclass messages is correct

 All inherited accessor events are appropriate in the context of

the subclass

 Messages sent to objects that are variables in a guard

expression do not have side effects on the class under test

slide-38
SLIDE 38

SEI–38

Control faults question

 What types of control faults can occur in a state

machine?

slide-39
SLIDE 39

SEI–39

Control faults for state machines

 An incorrect sequence of events is accepted  An incorrect sequence of outputs is produced

slide-40
SLIDE 40

SEI–40

State control faults question

 What types of state control faults can occur in a

statechart?

slide-41
SLIDE 41

SEI–41

Types of state control faults

Missing transition Incorrect transition Missing action Incorrect action Trap door Sneak path Corrupt state Illegal message failure

Occur individually or any nightmare combination Are all combinations possible?

slide-42
SLIDE 42

SEI–42

Relationship among state control faults

slide-43
SLIDE 43

SEI–43

Missing transition question

 How can you tell from the behaviour of a statechart that

there is a missing transition?

slide-44
SLIDE 44

SEI–44

Missing transition

 How can you tell from the behaviour of a statechart that

there is a missing transition?

 Does not respond to a valid event-state pair  Resultant state is incorrect but not corrupt

slide-45
SLIDE 45

SEI–45

Missing transition – 2

slide-46
SLIDE 46

SEI–46

Incorrect transition question

 How can you tell from the behaviour of a statechart that

there is an incorrect transition?

slide-47
SLIDE 47

SEI–47

Incorrect transition

 How can you tell from the behaviour of a statechart that

there is an incorrect transition?

 Implementation behaves as if an incorrect resultant state

has been reached

 Resultant state is incorrect but not corrupt

slide-48
SLIDE 48

SEI–48

Incorrect transition – 2

slide-49
SLIDE 49

SEI–49

Missing action question

 How can you tell from the behaviour of a statechart that

there is a missing action?

slide-50
SLIDE 50

SEI–50

Missing action

 How can you tell from the behaviour of a statechart that

there is a missing action?

 Implementation does not have an action for a transition

 Can have incorrect output  Later be in an incorrect state  Wait forever for the missing action to occur

slide-51
SLIDE 51

SEI–51

Missing action – 2

If simulateVolley() is missing, system hangs

slide-52
SLIDE 52

SEI–52

Incorrect action question

 How can you tell from the behaviour of a statechart that

there is an incorrect action?

slide-53
SLIDE 53

SEI–53

Incorrect action

 How can you tell from the behaviour of a statechart that

there is an incorrect action?

 Implementation produces the wrong action for a transition

 Different from incorrect output for an action  Have incorrect output  Later be in an incorrect state

slide-54
SLIDE 54

SEI–54

Incorrect action – 2

Instead of simulateVolley()

slide-55
SLIDE 55

SEI–55

Trap door question

 How can you tell from the behaviour of a statechart that

there is a trap door?

slide-56
SLIDE 56

SEI–56

Trap door

 How can you tell from the behaviour of a statechart that

there is a trap door?

 Implementation accepts an entry event that is not defined in

the specification

 Can result in

 Incorrect output  Corrupt state  Enter wrong state  Or combination

slide-57
SLIDE 57

SEI–57

Trap door – 2

Transition enters the system.

slide-58
SLIDE 58

SEI–58

Trap door – 3

 Can result from

 Obsolete features that were not removed  Inherited features that are inconsistent with the

requirements of the subclass

 "Undocumented " features added by the developer for

debugging purposes

 Sabotage for criminal or malicious purposes

slide-59
SLIDE 59

SEI–59

Sneak path question

 How can you tell from the behaviour of a statechart that

there is a sneak path?

slide-60
SLIDE 60

SEI–60

Sneak path

How can you tell from the behaviour of a statechart that there is a sneak path?

 Implementation for a state accepts an event that is

 Illegal  Or unspecified

 Can result in

 Incorrect output  Corrupt state

 Enter wrong state

 Or combination

slide-61
SLIDE 61

SEI–61

Sneak path

Transition is within the system.

slide-62
SLIDE 62

SEI–62

Sneak path – 3

 Can result from

 Obsolete features that were not removed  Inherited features that are inconsistent with the

requirements of the subclass

 "Undocumented" features added by the developer for

debugging purposes

 Sabotage for criminal or malicious purposes

slide-63
SLIDE 63

SEI–63

Corrupt state question

 How can you tell from the behaviour of a statechart that

there is a corrupt state?

slide-64
SLIDE 64

SEI–64

Corrupt state

 How can you tell from the behaviour of a statechart that

there is a corrupt state?

 Implementation computes a state that is not valid

 Either the class invariant or state invariant is violated  Due to coding and / or design errors

slide-65
SLIDE 65

SEI–65

Corrupt state – 2

Incorrect transition to corrupt state

slide-66
SLIDE 66

SEI–66

Incorrect Composite Behaviour

 Misuse of inheritance with modal classes can lead to state

control bugs

 Subclasses can conflict with sequential requirements of a

superclass

 Need to test beyond the scope of one class

slide-67
SLIDE 67

SEI–67

Incorrect Composite Behaviour – 2

 Bugs occur for the following reasons

 Missing or incorrect redefinition of a method  Subclass extension of the local state conflicts with a

superclass state

slide-68
SLIDE 68

SEI–68

Incorrect Composite Behaviour – 3

 Bugs occur for the following reasons – cont'd

 Subclass fails to retarget a superclass transition

 Switches to an incorrect or undefined superclass state

 Order of evaluation of guards and preconditions is

incorrect or sensitive to the order of evaluation

 Guards behave as if an extra state exists

slide-69
SLIDE 69

SEI–69

Incorrect Composite Behaviour – 4

 Bugs occur for the following reasons – contʼd

 Order of guard evaluation produces a side effect in the

subclass that is not present in the superclass

 Default name scope resolution results in guard parameters

being bound to the wrong subclass or superclass methods

slide-70
SLIDE 70

SEI–70

Static checking question

 The checklists are based on doing static checking on

FSMs, which implies looking at FSM diagrams.

 What else can you do to help with static checking?

slide-71
SLIDE 71

SEI–71

Static checking question – 2

 The checklists are based on doing static checking on

FSMs, which implies looking at FSM diagrams.

 What else can you do to help with static checking?

 Change to another representation

slide-72
SLIDE 72

SEI–72

Line-end conversion example

slide-73
SLIDE 73

SEI–73

Line-end conversion example – 2

Missing transaction is obvious