Build State Transition Tests
Purpose
Verify that a lifecycle allows exactly the transitions it should, under the right conditions and roles, and rejects every other one, since illegal transitions are a frequent source of data corruption and security defects.
When to use
- An entity has statuses and actions allowed only in some statuses.
- Workflows include approvals, timeouts, retries, cancellations or reopenings.
- An API exposes status-changing endpoints that could be called in the wrong order.
When not to use
- The state model itself must be designed or documented for business. Use
state-model.
- Outcome depends only on current input combinations, not status. Use
decision-table-testing.
- You need all scenarios of a feature at high level. Use
test-scenarios-from-requirements.
Inputs
Required:
- States and allowed transitions, or a description of the workflow.
Optional, improves quality:
- Guards (conditions, roles), actions on transition (notifications, stock, audit), timeouts.
- Existing diagram or status field values.
If the workflow description is missing, ask for it. Transitions not stated as allowed or forbidden become open questions.
Process
- List states including initial, final and implicit ones (e.g. "Expired" after a timeout, "Deleted").
- List events/triggers: user actions, system events, timers, external callbacks.
- Build the state transition table: for each valid transition give from-state, event, guard, to-state, actions.
- Draw or describe the diagram in text (e.g. a Mermaid state diagram) so it can be reviewed.
- Build the full state x event matrix; every empty cell is a candidate invalid transition. Decide expected behavior: rejected with message, ignored, or
[UNKNOWN].
- Derive 0-switch tests: one test per valid transition, including guard true/false variants and role variants.
- Derive invalid transition tests for high-risk cells (terminal states, financial effects, security-relevant roles), including direct API calls that bypass the UI.
- Derive 1-switch or longer sequences for risky paths: reopen after reject, cancel after approve, retry after failure, loops.
- Add timing and concurrency cases: timeout at boundary, two actors triggering conflicting events simultaneously.
- Verify side effects per transition: audit trail, notifications, dependent entities.
- List open questions for undefined cells.
- Label inferred transitions
[ASSUMPTION]; if the user continues, suggest test-case-writing for executable cases or api-test-design when transitions are driven through an API.
Output format
# State Transition Tests: <entity / workflow>
## States and Events
## Transition Table
| # | From | Event | Guard | To | Actions |
## Diagram
<text or Mermaid stateDiagram>
## State x Event Matrix
| State \ Event | E1 | E2 | ... | (to-state, "Reject", or [UNKNOWN])
## Tests
| Test | Type (valid / invalid / sequence) | Path | Data / role | Expected |
## Open Questions
Quality checklist
Common pitfalls
- Testing only through the UI, where invalid buttons are hidden. Call the underlying API or service directly.
- Forgetting timer-driven and system-driven transitions.
- Ignoring concurrent transitions (approve and cancel at the same moment).
Example
Input: "Draft, Submitted, Approved, Rejected, Cancelled, Ordered; only requester cancels, only before Ordered."
Excerpt of output:
| 5 | Approved | Cancel | actor = requester | Cancelled | Notify approver |
| ST-12 | Invalid | Ordered → Cancel | requester | Rejected, status unchanged |
| ST-15 | Invalid | Approved → Cancel | approver (not requester) | Rejected with authorization error |
- Open question: Can a Rejected request be edited and resubmitted, or is a new request needed?
1---2name: state-transition-testing3description: "Models an entity or workflow as states, events, guards and actions, then derives tests for all valid transitions, invalid transitions (state-event pairs that must be rejected) and key transition sequences (0-switch and 1-switch coverage). Use when behavior depends on status or history, such as orders, applications, approvals, accounts, sessions or devices, or when someone asks to test a workflow or lifecycle."4license: MIT5metadata:6 source: https://skillmd.com/skills/muratdincer/state-transition-testing7 version: "1.0.0"8 language: en9 category: 06-quality10 role: qa-analyst11 area: design12 title: "Build state transition tests"13 related: "state-model, decision-table-testing, test-case-writing, test-scenarios-from-requirements, api-test-design"14 prompt: "Create state transition tests for our purchase request: Draft, Submitted, Approved, Rejected, Cancelled, Ordered. Only the requester can cancel, only before Ordered."15---1617# Build State Transition Tests1819## Purpose20Verify that a lifecycle allows exactly the transitions it should, under the right conditions and roles, and rejects every other one, since illegal transitions are a frequent source of data corruption and security defects.2122## When to use23- An entity has statuses and actions allowed only in some statuses.24- Workflows include approvals, timeouts, retries, cancellations or reopenings.25- An API exposes status-changing endpoints that could be called in the wrong order.2627## When not to use28- The state model itself must be designed or documented for business. Use `state-model`.29- Outcome depends only on current input combinations, not status. Use `decision-table-testing`.30- You need all scenarios of a feature at high level. Use `test-scenarios-from-requirements`.3132## Inputs33Required:34- States and allowed transitions, or a description of the workflow.3536Optional, improves quality:37- Guards (conditions, roles), actions on transition (notifications, stock, audit), timeouts.38- Existing diagram or status field values.3940If the workflow description is missing, ask for it. Transitions not stated as allowed or forbidden become open questions.4142## Process431. List states including initial, final and implicit ones (e.g. "Expired" after a timeout, "Deleted").442. List events/triggers: user actions, system events, timers, external callbacks.453. Build the state transition table: for each valid transition give from-state, event, guard, to-state, actions.464. Draw or describe the diagram in text (e.g. a Mermaid state diagram) so it can be reviewed.475. Build the full state x event matrix; every empty cell is a candidate invalid transition. Decide expected behavior: rejected with message, ignored, or `[UNKNOWN]`.486. Derive 0-switch tests: one test per valid transition, including guard true/false variants and role variants.497. Derive invalid transition tests for high-risk cells (terminal states, financial effects, security-relevant roles), including direct API calls that bypass the UI.508. Derive 1-switch or longer sequences for risky paths: reopen after reject, cancel after approve, retry after failure, loops.519. Add timing and concurrency cases: timeout at boundary, two actors triggering conflicting events simultaneously.5210. Verify side effects per transition: audit trail, notifications, dependent entities.5311. List open questions for undefined cells.5412. Label inferred transitions `[ASSUMPTION]`; if the user continues, suggest `test-case-writing` for executable cases or `api-test-design` when transitions are driven through an API.5556## Output format57```markdown58# State Transition Tests: <entity / workflow>59## States and Events60## Transition Table61| # | From | Event | Guard | To | Actions |62## Diagram63<text or Mermaid stateDiagram>64## State x Event Matrix65| State \ Event | E1 | E2 | ... | (to-state, "Reject", or [UNKNOWN])66## Tests67| Test | Type (valid / invalid / sequence) | Path | Data / role | Expected |68## Open Questions69```7071## Quality checklist72- [ ] Every valid transition is covered by at least one test (0-switch coverage).73- [ ] Every cell of the state x event matrix has an expected behavior or is an open question.74- [ ] Terminal states are tested for rejection of all events.75- [ ] Guards are tested in both true and false variants, including role checks.76- [ ] Side effects are verified, not only the resulting status.77- [ ] All checks pass; if any fails, revise the output and re-run this checklist before answering.7879## Common pitfalls80- Testing only through the UI, where invalid buttons are hidden. Call the underlying API or service directly.81- Forgetting timer-driven and system-driven transitions.82- Ignoring concurrent transitions (approve and cancel at the same moment).8384## Example85Input: "Draft, Submitted, Approved, Rejected, Cancelled, Ordered; only requester cancels, only before Ordered."8687Excerpt of output:88| 5 | Approved | Cancel | actor = requester | Cancelled | Notify approver |89| ST-12 | Invalid | Ordered → Cancel | requester | Rejected, status unchanged |90| ST-15 | Invalid | Approved → Cancel | approver (not requester) | Rejected with authorization error |91- Open question: Can a Rejected request be edited and resubmitted, or is a new request needed?