State Transition Testing – Diagram & Technique (Example)

What is State Transition Testing?

State Transition Testing is a black box testing technique in which changes made in input conditions cause state changes or output changes in the Application under Test(AUT). State transition testing helps to analyze behaviour of an application for different input conditions. Testers can provide positive and negative input test values and record the system behavior.

It is the model on which the system and the tests are based. Any system where you get a different output for the same input, depending on what has happened before, is a finite state system.

State Transition Testing Technique is helpful where you need to test different system transitions.

When to Use State Transition?

  • This can be used when a tester is testing the application for a finite set of input values.
  • When the tester is trying to test sequence of events that occur in the application under test. I.e., this will allow the tester to test the application behavior for a sequence of input values.
  • When the system under test has a dependency on the events/values in the past.

When to Not Rely On State Transition?

  • When the testing is not done for sequential input combinations.
  • If the testing is to be done for different functionalities like exploratory testing

Four Parts Of State Transition Diagram

There are 4 main components of the State Transition Model as below

1) States that the software might get

2) Transition from one state to another

3) Events that origin a transition like closing a file or withdrawing money

4) Actions that result from a transition (an error message or being given the cash.)

State Transition Diagram and State Transition Table

There are two main ways to represent or design state transition, State transition diagram, and state transition table.

In state transition diagram the states are shown in boxed texts, and the transition is represented by arrows. It is also called State Chart or Graph. It is useful in identifying valid transitions.

In state transition table all the states are listed on the left side, and the events are described on the top. Each cell in the table represents the state of the system after the event has occurred. It is also called State Table. It is useful in identifying invalid transitions.

How to Make a State Transition (Examples of a State Transition)

Example 1:

Let’s consider an ATM system function where if the user enters the invalid password three times the account will be locked.

In this system, if the user enters a valid password in any of the first three attempts the user will be logged in successfully. If the user enters the invalid password in the first or second try, the user will be asked to re-enter the password. And finally, if the user enters incorrect password 3rd time, the account will be blocked.

State transition diagram

In the diagram whenever the user enters the correct PIN he is moved to Access granted state, and if he enters the wrong password he is moved to next try and if he does the same for the 3rd time the account blocked state is reached.

State Transition Table

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, state is transitioned to S5 which is Access granted. And if the user enters a wrong password he is moved to next state. If he does the same 3rd time, he will reach the account blocked state.

Example 2:

Check this State Transition Testing video, before you refer the example below:

Click here if the video is not accessible

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

State Transition Graph

It gives you the access to the application with correct password and login name, but what if you entered the wrong password.

The application allows three attempts, and if users enter the wrong password at 4th attempt, the system closes the application automatically.

The State Graphs helps you determine valid transitions to be tested. In this case, testing with the correct password and with an incorrect password is compulsory. For the test scenarios, log-in on 2nd, 3rd and 4th attempt anyone could be tested.

You can use State Table to determine invalid system transitions.

In a State Table, all the valid states are listed on the left side of the table, and the events that cause them on the top.

Each cell represents the state system will move to when the corresponding event occurs.

For example, while in S1 state you enter a correct password you are taken to state S6 (Access Granted). Suppose if you have entered the wrong password at first attempt you will be taken to state S3 or 2nd Try.

Likewise, you can determine all other states.

Two invalid states are highlighted using this method. Suppose you are in state S6 that is you are already logged into the application, and you open another instance of flight reservation and enter valid or invalid passwords for the same agent. System response for such a scenario needs to be tested.

Advantages and Disadvantages of State Transition Technique

Advantages Disadvantages
This testing technique will provide a pictorial or tabular representation of system behavior which will make the tester to cover and understand the system behavior effectively. The main disadvantage of this testing technique is that we can’t rely in this technique every time. For example, if the system is not a finite system (not in sequential order), this technique cannot be used.
By using this testing, technique tester can verify that all the conditions are covered, and the results are captured Another disadvantage is that you have to define all the possible states of a system. While this is all right for small systems, it soon breaks down into larger systems as there is an exponential progression in the number of states.

Summary:

  • State Transition testing is defined as the testing technique in which changes in input conditions cause’s state changes in the Application under Test.
  • In Software Engineering, State Transition Testing Technique is helpful where you need to test different system transitions.
  • Two main ways to represent or design state transition, State transition diagram, and State transition table.
  • In state transition diagram the states are shown in boxed texts, and the transition is represented by arrows.
  • In state transition table all the states are listed on the left side, and the events are described on the top.
  • This main advantage of this testing technique is that it will provide a pictorial or tabular representation of system behavior which will make the tester to cover and understand the system behavior efficiently.
  • The main disadvantage of this testing technique is that we can’t rely in this technique every time.