In our last article, we saw ‘Cause and effect graph’ test case writing technique. Today let’s move to next dynamic test case writing method – State transition technique.
Note – The test design techniques mentioned here may seem difficult but once you get hold of it, it becomes very easy to implement and reuse, increasing productivity and test coverage.
What is State transition testing technique?
State transition technique is a dynamic testing technique, which is used when the system is defined in terms of a finite number of states and the transitions between the states is governed by the rules of the system.
Or in other words, this technique is used when features of a system are represented as states which transforms to other state. The transformations are determined by the rules of the software. The pictorial representation can be shown as:
So here we see that an entity transitions from State 1 to State 2 because of some input condition, which leads to an event and results to an action and finally gives the output.
To explain it with an example:
You visit an ATM and withdraw $1000. You get your cash. Now you run out of balance and make exactly the same request of withdrawing $1000. This time ATM refuses to give you the money because of insufficient balance. So here the transition, which caused the change in state is the earlier withdrawal
What You Will Learn:
State Transition Testing Example in Software testing:
In practical scenario, testers are normally given the state transition diagrams and we are required to interpret it. These diagrams are either given by the Business Analysts or a stakeholder and we use these diagrams to determine our test cases.
Let’s consider the below situation:
Software name – Manage_display_changes
Specifications – The software responds to input requests to change display mode for a time display device.
The display mode can be set to one of the four values:
- Two corresponding to displaying either the time or date.
- The other two when altering either the time or the date.
The different states are as follows:
Change Mode (CM)
Activation of this shall cause the display mode to move between “display time (T)” and “display date (D)”.
If the display mode is set to T or D, then a “reset” shall cause the display mode to be set to “alter time (AT)” or “alter date (AD)” modes.
Time Set (TS)
Activation of this shall cause the display mode to return to T from AT.
Date Set (DS)
Activation of this shall cause the display mode to return to D from AD.
State transition diagram is shown as:
Now, let’s move to interpret it:
1) Various states are:
- Display Time(S1),
- Change Time(S3),
- Display Date(S2) and
- Change Date (S4).
2) Various Inputs are:
- Change Mode(CM),
- Reset (R),
- Time Set(TS),
- Date Set(DS).
3) Various Outputs are:
- Alter Time(AT),
- Display Time(T),
- Display Date(D),
- Alter Date (AD).
4) Changed States are:
- Display Time(S1),
- Change Time (S3),
- Display Date (S2) and
- Change Date (S4).
Write all the start state. For this, take one state at a time and see how many arrows are coming out from it.
- For State S1, there are two arrows coming out of it. One arrow is going to state S3 and other arrow is going to state S2.
- For State S2 – There are 2 arrows. One is going to State S1 and other going to S4
- For State S3 – Only 1 arrow is coming out of it, going to state S1
- For State S4 – Only 1 arrow is coming out of it, going to state S2
Let’s put this into our table:
Since, for state S1 and S2 there are two arrows coming out, we have written it twice.
For each state, write down their final state.
- For state S1 – The final states are S2 and S3
- For State S2 – The final states are S1 and S4
- For State S3 – Final state is S1
- For State S4 – Final State is S2
Put this in the table as output / resultant state.
For each start state and its corresponding finish state, write down the input and output conditions
– For state S1 to go to state S2, the input is Change Mode (CM) and output is Display Date(D) shown below:
In a similar way, write down the Input conditions and its output for all the states as follows:
Now add the test case ID for each tests shown below:
Now let’s convert it to a formal test cases:
(Click image to enlarge)
In this way all the remaining test cases can be derived. I assume the other attributes of the test cases like preconditions, severity, priority, environment, build etc. are also included in the test case.
Summarizing the steps once again:
- Identify the initial states and their final state based on the lines/arrows that are coming out of the initial state
- For each initial state, find out the input condition and the output result
- Mark each set as a separate test case.
State Transition testing is a unique test approach for testing complex applications, which would increase test execution productivity without compromising on test coverage.
About the author: This is a guest article by Shilpa Chatterjee Roy. She is working in software testing field for the past 8.5 years in various domains.
Want more examples?
If you want more examples of State Transition Testing technique in bigger software applications, please read this post: