state transition testing

33
1 State-Transition Testing State-Transition Testing Example Example State-Transition diagrams State-Transition diagrams are an excellent tool to are an excellent tool to capture certain types of capture certain types of system requirements and to system requirements and to document internal system document internal system design. design. These diagrams document the These diagrams document the events that come into and are events that come into and are processed by a system as well processed by a system as well as the system's responses. as the system's responses.

Upload: rakesh

Post on 10-Apr-2015

3.375 views

Category:

Documents


3 download

DESCRIPTION

A test case design technique in which test cases are designed to execute state transitions.State transition testing uses the same principles as the State Transition Diagramming design technique. State transition testing focuses on the testing of transitions from one state (e.g., open, closed) of an object (e.g., an account) to another state. Incorporate the state transition testing preparation into the test scenario building process. For example, include tests of an account transitioning from open to closed and an account transitioning from closed to open (e.g., account closed in error).

TRANSCRIPT

Page 1: State Transition Testing

11

State-Transition Testing ExampleState-Transition Testing Example

State-Transition diagrams are an excellent State-Transition diagrams are an excellent tool to capture certain types of system tool to capture certain types of system requirements and to document internal requirements and to document internal system design. system design.

These diagrams document the events that These diagrams document the events that come into and are processed by a system as come into and are processed by a system as well as the system's responses. well as the system's responses.

Page 2: State Transition Testing

22

Reservation system exampleReservation system example 1- 1- Make a reservationMake a reservation Provide information including departure and Provide information including departure and

destination cities, dates, and times. destination cities, dates, and times.

A reservation agent uses that information to make a A reservation agent uses that information to make a reservation. reservation.

At that point, the At that point, the ReservationReservation is in the is in the MadeMade state. state.

The system creates and starts a timer. The system creates and starts a timer.

If this timer expires before the reservation is paid for, If this timer expires before the reservation is paid for, the reservation is cancelled by the system. the reservation is cancelled by the system.

Page 3: State Transition Testing

33

The Reservation is MadeThe Reservation is Made

giveInfo, is an event that comes into the system from the outside world.

The command after the "/" denotes an action of the system; in this case startPayTimer.

Page 4: State Transition Testing

44

2- Pay for the Reservation - PayMoney2- Pay for the Reservation - PayMoney

The Reservation transitions to the Paid state.

Events may have parameters associated with them. For example, Pay Money may indicate Cash, Check, Debit Card, or Credit Card

Page 5: State Transition Testing

55

3- Print the ticket: - print3- Print the ticket: - print

The Reservation transitions to the Ticketed state.

Page 6: State Transition Testing

66

4- Give ticket4- Give ticket giveTicketgiveTicket to the gate agent to board the plane to the gate agent to board the plane

The Reservation transitions to the Used state.The Reservation transitions to the Used state.

Page 7: State Transition Testing

77

4- Give ticket (Cont.)4- Give ticket (Cont.)

The path ends

Page 8: State Transition Testing

88

5- Cancel for no payment by the ‘PayTimer’5- Cancel for no payment by the ‘PayTimer’ If the If the ReservationReservation is not paid the is not paid the PayTimerPayTimer expires and the expires and the

Reservation is Reservation is cancelledcancelled for non-payment. for non-payment.

Page 9: State Transition Testing

99

6- Cancel by customer6- Cancel by customer When the customer asks to When the customer asks to cancelcancel the the ReservationReservation

Cancel the Reservation from the Made state

Page 10: State Transition Testing

1010

7- Cancel by customer after payment7- Cancel by customer after payment A A ReservationReservation is cancelled from the is cancelled from the PaidPaid state, a state, a RefundRefund

should be generated and leave the systemshould be generated and leave the system

Cancellation from the Paid state

Page 11: State Transition Testing

1111

8- Customer cancels after receiving the ticket8- Customer cancels after receiving the ticket

From the From the TicketedTicketed state the customer can cancel the state the customer can cancel the ReservationReservation. .

In that case a In that case a RefundRefund should be generated. should be generated.

The airline will generate a refund but only when it The airline will generate a refund but only when it receives the printed receives the printed TicketTicket from the customer. This from the customer. This introduces one new notational element—square introduces one new notational element—square brackets [] that contain a conditional that can be brackets [] that contain a conditional that can be evaluated either evaluated either TrueTrue or or False.False.

This conditional acts as a guard allowing the This conditional acts as a guard allowing the transition only if the condition is true.transition only if the condition is true.

Page 12: State Transition Testing

1212

8- Customer cancels after receiving the ticket (cont.)8- Customer cancels after receiving the ticket (cont.)

Cancellation from the Ticketed state

Page 13: State Transition Testing

1313

State-Transition TablesState-Transition Tables State-transition tables may be easier to use in a State-transition tables may be easier to use in a

complete and systematic manner. complete and systematic manner.

State-transition tables consist of four columnsState-transition tables consist of four columns—Current State, Event, Action, and Next —Current State, Event, Action, and Next State.State.

Page 14: State Transition Testing

1414

Page 15: State Transition Testing

1515

Page 16: State Transition Testing

1616

Page 17: State Transition Testing

1717

Page 18: State Transition Testing

1818

State-Transition Tables (Cont.)State-Transition Tables (Cont.)

The advantage of a state-transition table is that it lists The advantage of a state-transition table is that it lists all possible state-transition combinations, not just the all possible state-transition combinations, not just the valid ones.valid ones.

When testing critical, high-risk systems such as When testing critical, high-risk systems such as avionics or medical devices, testing every state-avionics or medical devices, testing every state-transition pair may be required, including those that transition pair may be required, including those that are not valid. are not valid.

Creating a state-transition table often unearths Creating a state-transition table often unearths combinations that were not identified, documented, or combinations that were not identified, documented, or dealt with in the requirements. It is highly beneficial dealt with in the requirements. It is highly beneficial to discover these defects before coding begins.to discover these defects before coding begins.

Page 19: State Transition Testing

1919

State-Transition Tables (Cont.)State-Transition Tables (Cont.)

Using a state-transition table can help detect Using a state-transition table can help detect defects in implementation that enable invalid defects in implementation that enable invalid paths from one state to another. paths from one state to another.

The disadvantage of such tables is that they The disadvantage of such tables is that they become very large very quickly as the number become very large very quickly as the number of states and events increases. of states and events increases.

In addition, the tables are generally sparse; that In addition, the tables are generally sparse; that is, most of the cells are empty.is, most of the cells are empty.

Page 20: State Transition Testing

2020

Creating Test CasesCreating Test Cases1.1. Create a set of test cases such that all Create a set of test cases such that all

states are "visited" at least once under states are "visited" at least once under testtest. The set of three test cases shown below . The set of three test cases shown below meets this requirement. Generally this is a meets this requirement. Generally this is a weak level of test coverage.weak level of test coverage.

Page 21: State Transition Testing

2121

A set of test cases that "visit" each stateA set of test cases that "visit" each state

Page 22: State Transition Testing

2222

Creating Test Cases (Cont.)Creating Test Cases (Cont.)

2. 2. Create a set of test cases such that all events Create a set of test cases such that all events are triggered at least once under test.are triggered at least once under test. Note Note that the test cases that cover each event can be that the test cases that cover each event can be the same as those that cover each state. Again, the same as those that cover each state. Again, this is a weak level of coverage.this is a weak level of coverage.

Page 23: State Transition Testing

2323

A set of test cases that trigger all events at least onceA set of test cases that trigger all events at least once

Page 24: State Transition Testing

2424

Creating Test Cases (Cont.)Creating Test Cases (Cont.)3. Create a set of test cases such that all paths are executed at 3. Create a set of test cases such that all paths are executed at

least once under test.least once under test. While this level is the most preferred because of its level of coverage, it While this level is the most preferred because of its level of coverage, it

may not be feasible. may not be feasible.

For example, given a system with two states, A and B, where A transitions For example, given a system with two states, A and B, where A transitions to B and B transitions to A. A few of the possible paths are:to B and B transitions to A. A few of the possible paths are:

AA→→BB AA→→BB→→AA AA→→BB→→AA→→BB→→AA→→BB AA→→BB→→AA→→BB→→AA→→BB→→AA ...... and so on forever. and so on forever.

Page 25: State Transition Testing

2525

3. Create a set of test cases such that all paths are executed at 3. Create a set of test cases such that all paths are executed at least once under test (Cont.)least once under test (Cont.)

Testing of loops such as this can be important if they Testing of loops such as this can be important if they may result in accumulating computational errors or may result in accumulating computational errors or resource loss (locks without corresponding releases, resource loss (locks without corresponding releases, memory leaks, etc.).memory leaks, etc.).

Page 26: State Transition Testing

2626

Creating Test Cases (Cont.)Creating Test Cases (Cont.)

4. Create a set of test cases such that all transitions 4. Create a set of test cases such that all transitions are exercised at least once under test. are exercised at least once under test. This level of This level of testing provides a good level of coverage without testing provides a good level of coverage without generating large numbers of tests. This level is generating large numbers of tests. This level is generally the one recommended.generally the one recommended.

Page 27: State Transition Testing

2727

A set of test cases that trigger all transitions at least A set of test cases that trigger all transitions at least

onceonce

Page 28: State Transition Testing

2828

4. A set of test cases that trigger all transitions at least 4. A set of test cases that trigger all transitions at least once (Cont.)once (Cont.)

Test cases can also be read directly from the state-transition Test cases can also be read directly from the state-transition table. The gray rows in the following table show all the valid table. The gray rows in the following table show all the valid transitions.transitions.

Page 29: State Transition Testing

2929

Page 30: State Transition Testing

3030

Page 31: State Transition Testing

3131

Page 32: State Transition Testing

3232

State-Transition Testing (Cont.)State-Transition Testing (Cont.) In addition, depending on the system risk, you may want to In addition, depending on the system risk, you may want to

create test cases for some or all of the invalid state/event pairs create test cases for some or all of the invalid state/event pairs to make sure the system has not implemented invalid paths.to make sure the system has not implemented invalid paths.

Applicability and LimitationsApplicability and Limitations State-Transition diagrams are excellent tools to capture State-Transition diagrams are excellent tools to capture

certain system requirements, namely those that describe certain system requirements, namely those that describe states and their associated transitions. These diagrams then states and their associated transitions. These diagrams then can be used to direct our testing efforts by identifying the can be used to direct our testing efforts by identifying the states, events, and transitions that should be tested.states, events, and transitions that should be tested.

State-Transition diagrams are not applicable when the State-Transition diagrams are not applicable when the system has no state or does not need to respond to real-time system has no state or does not need to respond to real-time events from outside of the system. events from outside of the system.

An example is a payroll program that reads an employee's time An example is a payroll program that reads an employee's time record, computes pay, subtracts deductions, saves the record, record, computes pay, subtracts deductions, saves the record, prints a paycheck, and repeats the process.prints a paycheck, and repeats the process.

Page 33: State Transition Testing

3333

State-Transition Testing (Cont.)State-Transition Testing (Cont.)SummarySummary

State-Transition diagrams direct our testing efforts by State-Transition diagrams direct our testing efforts by identifying the states, events, actions, and transitions that identifying the states, events, actions, and transitions that should be tested. Together, these define how a system interacts should be tested. Together, these define how a system interacts with the outside world, the events it processes, and the valid with the outside world, the events it processes, and the valid and invalid order of these events.and invalid order of these events.

A state-transition diagram is not the only way to document A state-transition diagram is not the only way to document system behaviour. They may be easier to comprehend, but system behaviour. They may be easier to comprehend, but state-transition tables may be easier to use in a complete and state-transition tables may be easier to use in a complete and systematic manner.systematic manner.

The generally recommended level of testing using state-The generally recommended level of testing using state-transition diagrams is to create a set of test cases such that all transition diagrams is to create a set of test cases such that all transitions are exercised at least once under test. transitions are exercised at least once under test.

In high-risk systems, you may want to create even more test In high-risk systems, you may want to create even more test cases, approaching all paths if possible.cases, approaching all paths if possible.