State Transition Testing is a software testing technique that allows us to verify the expected execution sequences of each state against the input used in executing states. Generally, State transition occurs when there are ifs or switches/case statements in the program logic. For example: To test a program that has the following condition statement: If (age <18) Then, “Adult” Else, then (age <35) Then, “Teenager” Else, if (age <55) Then, “Senior Citizen” else, “Young Person”.
In this state transition test design technique the test cases are designed to represent all possible state transitions that can occur. Here we will first determine all the possible transitions that can occur in the program logic and then design test cases for each of those transitions. The objective is to achieve 100 percent testing coverage, i.e., all possible state transitions from every possible entry condition should be tested.
State Transition Test Design Technique Example
Below I have explained how the state transition testing technique can be applied on a simple example:
For the above program, we can observe that there are two possible entry points and the state transitions in this program logic are summarized below:
The test cases required to cover all the possible states for each of these conditions will be designed with a valid combination of input. For example, if the intention is to test all possible state transitions from condition 1, then we will design test cases with the following inputs:
Similarly, for condition 2, we will design test cases with the following input combination.
To get a better understanding of State Transition Testing, let us take an example of a program written in C Language to understand it better. The source code is as follows:
/* Program to display numbers from 0 to 10 on the screen */
#include <stdio.h>
int main() {
printf(“Enter a number: “);
scanf(“%d”,&x);
if(x<0) { /* if x is less than 0 */
printf(“Negative value %d is not allowed”,x);/* Prints out message */
else { /*Display number on the screen */
printf(“%d is a positive number”,x); } /* Prints out a number*/
return(0);
}
The above program has two entry points and for this example, we will test all possible state transitions from both these conditions. The following table shows how the possible states are listed for each of these conditions.
The following table shows what will be the input to represent a state transition:
Now let us create two separate test cases and see how we can design our test cases for this program.
We have designed four test cases that cover all the possible state transitions from both entry points. For this program, we can achieve 100 percent testing coverage by creating eight test cases.
The advantages of using state transition testing are:
State Transition Testing is a very good approach for achieving 100% coverage in the application under test and hence it is better than mutation or data flow-based testing. It also mimics real-life situations more closely.
The disadvantages of using state transition testing are:
To get 100 percent coverage, we need to test a large number of input combinations. This will lead to exhaustive testing. The input combinations might be difficult to generate and hence this may lead to time-consuming tests.
Testing for particular requirements must be done by checking if the program handles that specific situation properly.
The coverage of each and every path may not be achieved with state transition testing. Other techniques can achieve 100% coverage such as branch testing or condition-decision coverage, but these approaches require more time for program design.
Methodology: Phase wise approach to State Transition Testing
Modeling Technique: State Transition Diagram
Tools: State Transition Testing can be done using commercial tools like Quicktest Professional, QTP which supports state transition testing.
Advantages: The automation of state transition testing will give the freedom to test any number of test cases in any order. This will enhance the performance and efficiency of a tester.
Disadvantages: State Transition Testing is very resource-consuming and time-consuming. There are also certain limitations on the type of programs that can be tested using this approach as it is difficult to cover all possible states from a given entry condition of a program. Also, this approach could lead to exhaustive testing which may not be necessary for small and medium applications but would be useful for large applications.
State Transition Testing has its advantages and disadvantages, but this method will certainly enhance the efficiency of a tester by helping him automate repetitive test cases for any number of inputs to an application in a given way.
Leave a Reply