State Transition Testing with Example

โšก Smart Summary

State Transition Testing is a black-box technique that validates how an application moves between states as input conditions change. This tutorial explains the four diagram parts, the difference between state diagrams and tables, and worked ATM and login examples for testers.

  • ๐Ÿ”„ Core Idea: The technique checks system behavior when the same input produces different outputs based on prior events (a finite-state system).
  • ๐Ÿงฉ Four Building Blocks: Every model is built from States, Transitions, Events, and Actions.
  • ๐Ÿ—บ๏ธ Diagram vs Table: Diagrams reveal valid transitions; tables expose invalid transitions.
  • ๐Ÿง Practical Examples: ATM PIN lockout and flight-reservation login demonstrate real coverage.
  • ๐Ÿค– AI Enablement: AI tools auto-generate state models from requirements and flag missing or invalid transitions.

State Transition Testing โ€” States

What is State Transition Testing?

State Transition Testing is a black-box testing technique in which changes in input conditions cause state changes or output changes in the Application Under Test (AUT). It helps analyze the behavior of an application for different input conditions, and testers can provide positive and negative input values while recording the system’s behavior.

It is based on the model on which the system and the tests are built. Any system where you get a different output for the same input โ€” depending on what happened before โ€” is a finite-state system. The State Transition Testing technique is helpful where you need to test different system transitions.

When to Use State Transition Testing

  • When a tester is testing the application for a finite set of input values.
  • When the tester is testing a sequence of events that occur in the AUT, allowing the application’s behavior to be checked for a sequence of input values.
  • When the system under test depends on events or values from the past.

When Not to Rely on State Transition Testing

  • When the testing is not done for sequential input combinations.
  • When the testing targets different functionalities, such as exploratory testing.

Four Parts of a State Transition Diagram

There are four main components of the State Transition model, described below.

1) States that the software might reach.

State Transition Testing โ€” States

2) Transition from one state to another.

State Transition Testing โ€” Transition

3) Events that trigger a transition, such as closing a file or withdrawing money.

State Transition Testing โ€” Events

4) Actions that result from a transition, such as an error message or being given cash.

State Transition Testing โ€” Actions

State Transition Diagram vs State Transition Table

There are two main ways to represent or design state transition: the state transition diagram and the state transition table.

Aspect State Transition Diagram State Transition Table
Also called State Chart / Graph State Table
Representation Boxes for states, arrows for transitions Grid of states (rows) and events (columns)
Best for identifying Valid transitions Invalid transitions
Each cell shows โ€” The state reached after an event occurs

How to Make a State Transition (Examples)

Example 1: ATM PIN Lockout

Consider an ATM system function where, if the user enters the invalid password three times, the account is locked.

In this system, if the user enters a valid password in any of the first three attempts, the user is logged in successfully. If the user enters the invalid password on the first or second try, they are asked to re-enter it. Finally, if the user enters the incorrect password a third time, the account is blocked.

State Transition Diagram (Example 1)

ATM PIN state transition diagram

In the diagram, whenever the user enters the correct PIN, they move to the Access Granted state. If they enter the wrong password, they move to the next try, and if they do the same a third time, the Account Blocked state is reached.

State Transition Table (Example 1)

State Correct PIN Incorrect PIN
S1) Start S5 S2
S2) 1st attempt S5 S3
S3) 2nd attempt S5 S4
S4) 3rd attempt S5 S6
S5) Access Granted โ€“ โ€“
S6) Account Blocked โ€“ โ€“

In the table, when the user enters the correct PIN, the state transitions to S5 (Access Granted). If the user enters a wrong password, they move to the next state, and after the third wrong attempt they reach the Account Blocked state.

Example 2: Flight Reservation Login

In the flight reservation login screen, you must enter the correct agent name and password to access the flight reservation application.

Flight reservation State Transition Graph

State Transition Graph

The application allows three attempts; if the user enters the wrong password on the fourth attempt, the system closes the application automatically.

The State Graph helps you determine valid transitions to be tested. Testing with both the correct and an incorrect password is compulsory, and for the test scenarios, logging in on the 2nd, 3rd, or 4th attempt could each be tested. You can use a State Table to determine invalid system transitions.

Flight reservation State Transition Table

In a State Table, all valid states are listed on the left and the events that cause them across the top. Each cell shows the state the system moves to when the event occurs. For example, in state S1, a correct password takes you to S6 (Access Granted); a wrong password on the first attempt takes you to S3 (2nd Try). Likewise, you can determine all other states.

Two invalid states are highlighted using this method. Suppose you are in state S6 (already logged in) and you open another instance of flight reservation and enter passwords for the same agent. The system response for such a scenario needs to be tested.

Advantages and Disadvantages of State Transition Technique

Advantages Disadvantages
Provides a pictorial or tabular representation of system behavior, helping the tester cover and understand the system effectively. Cannot be relied on every time โ€” for example, it does not suit systems that are not finite or sequential.
Lets the tester verify that all conditions are covered and the results are captured. Requires defining all possible states. This works for small systems but breaks down for larger ones due to the exponential growth in the number of states.

FAQs

State transition testing is a black-box technique that verifies how a system moves between states as input conditions change. It suits finite-state systems where the same input can produce different outputs depending on prior events.

The four parts are States (conditions the software can be in), Transitions (movement between states), Events (triggers that cause a transition), and Actions (results of a transition, such as a message or output).

A state transition diagram uses boxes and arrows and is best for identifying valid transitions. A state table lists states against events in a grid and is best for spotting invalid transitions.

Avoid it when inputs are not sequential or when doing exploratory testing of varied functionalities. It also breaks down for very large systems because the number of states grows exponentially.

0-switch coverage tests every single valid transition once. 1-switch coverage tests every pair of consecutive transitions. Higher switch coverage finds more sequence-related defects but requires more test cases.

It is a black-box technique. Test cases are derived from the expected external behavior of states and transitions, without needing knowledge of the internal source code of the application.

AI tools read requirements and automatically build state models, then generate test cases covering valid paths and edge transitions. This reduces manual modeling effort and improves coverage of complex sequences.

Yes. AI can analyze a state model and flag missing, unreachable, or invalid transitions by comparing it against expected behavior patterns, helping testers catch gaps that manual table reviews often miss.

Summarize this post with: