In software testing, state transition testing is a technique used to validate the behaviour of a system by analyzing its states, the events that trigger state changes, and the conditions or actions associated with those changes. It is particularly useful for systems where outputs depend on the sequence of past events or states (i.e., where the system’s behaviour is state-dependent).
State Transition Testing Basics
Models:
State Transition Diagram: Visual representation showing system states, valid transitions, events that trigger them, guard conditions, and resulting actions.
State Table: Tabular representation with states as rows and events (with guard conditions) as columns. It explicitly shows:
Valid transitions (target state and actions).
Invalid transitions (represented by empty cells).
2. Test Cases:
Represented as a sequence of events that drive state changes.
Cover several state transitions, including actions triggered by transitions.
Coverage Criteria
All States Coverage:
Objective: Ensure all system states are visited at least once.
Measurement: (Number of visited states)/(Total states)×100%\text{(Number of visited states)} / \text{(Total states)} \times 100\%(Number of visited states)/(Total states)×100%.
Strength: Weaker criterion as it may not require testing all transitions.
Objective: Ensure all valid state transitions are exercised.
Measurement: (Number of exercised valid transitions)/(Total valid transitions)×100%\text{(Number of exercised valid transitions)} / \text{(Total valid transitions)} \times 100\%(Number of exercised valid transitions)/(Total valid transitions)×100%.
Strength: Guarantees full state coverage but does not address invalid transitions.
3. All Transitions Coverage:
Objective: Ensure all valid and invalid transitions are covered.
Measurement: (Valid and invalid transitions tested)/(Total transitions)×100%\text{(Valid and invalid transitions tested)} / \text{(Total transitions)} \times 100\%(Valid and invalid transitions tested)/(Total transitions)×100%.
Strength: Strongest criterion, covering all states, valid transitions, and invalid transitions.
Purpose: Avoid fault masking by testing invalid transitions individually.
Comparative Strengths of Criteria
All States Coverage is weaker, as it doesn’t guarantee that all transitions are tested.
Valid Transitions Coverage ensures complete state and valid transition coverage, making it widely used.
All Transitions Coverage is the most rigorous, and essential for mission-critical and safety-critical systems, as it includes invalid transitions testing.
Key Takeaways
Guard Conditions and Actions are optional but provide additional detail for testers.
Testing invalid transitions helps detect and isolate faults, especially in critical systems.
The choice of coverage criteria depends on the system’s criticality and requirements.
Example of a Decision Table:
Here’s an example based on a login system with the following rules:
The user must provide a valid username.
The user must provide a valid password.
If both are valid, access is granted.
If either is invalid, access is denied.
Explanation:
Rule 1: Both username and password are valid → Access granted.
Rule 2: Username is valid but password is invalid → Access denied.
Rule 3: Username is invalid but password is valid → Access denied.
Rule 4: Both username and password are invalid → Access denied.