Skip to content
intermediate Phase 3 · Test Case Design Techniques

Decision Tables and State Transitions

Model logical rules and state sequences to cover complex condition combinations.

55m
0 problems
Topic Progress 0%

When Four Conditions Produce Sixteen Combinations: Decision Tables

A shipping-rule spec fits in five sentences: if the order is over $50, shipping is free; members get free shipping regardless of total; express shipping always costs $15 unless the member; frozen items require an express-capable carrier. Four conditions interact — order total, membership, express choice, frozen items — and the tester who writes cases one scenario at a time will cover the first three combinations she thinks of and ship. The combinatorics say why: four binary conditions make 2^4 = 16 combinations, and unaided scenario writing reliably covers fewer than half while being unable to prove which. A decision table is the technique that makes every combination visible and every test justified.

The table has the standard shape — conditions as rows, rules (combinations) as columns, actions per rule:

Condition R1 R2 R3 R4 ...
Order > $50 Y Y Y N
Member Y N N Y
Express N N Y N
Frozen items N N N N
Action: shipping cost 0 0 (>$50) $15→? 0 (member)

Building it is a four-pass drill. Pass 1 — list conditions and their possible values (each binary here: >$50 yes/no, member yes/no, express yes/no, frozen yes/no). Pass 2 — enumerate the combinations as columns: 16 columns for four binary conditions; ten conditions would be 1,024, which is why the next pass exists. Pass 3 — prune. Remove impossible rules (a cell combination that cannot occur — none here, but in insurance or banking specs they appear constantly, e.g., 'under 18 with a mortgage'), then merge duplicate rules — columns where the actions are identical and the differing conditions provably do not affect the outcome. The shipping table's four action-relevant conditions collapse significantly once free-shipping subsumption is applied (membership makes total irrelevant). Pass 4 — write the expected action per surviving column with the product owner in the room, because every disputed cell is a requirement defect found before coding.

Each surviving column becomes one test case, with concrete values chosen from the equivalence classes for each condition — the techniques compose: decision tables decide which combinations, equivalence partitioning picks which value in each cell. The payoff is provability: when a stakeholder asks 'did anyone test express shipping with frozen items and a non-member?', the table either contains the column with a test ID next to it or it doesn't — and 'the table says no' converts a panic into a backlog item.

Two disciplines keep tables honest. Incomplete tables are the real risk: 16 columns written, 11 'look similar', tested implicitly as 6 — a table with silent gaps is worse than no table because it launders partial coverage as proof. Number every column and require a test ID or an explicit 'impossible/merged — justification' note per column. Tables are living spec: when the rule changes mid-sprint (members now pay $5 for express), the changed column is the blast radius — the affected test cases are exactly the ones linked to it, which is traceability at its most practical.

State Transition Testing: Where the Defects Are Sequences, Not Values

Equivalence partitioning and decision tables share a blind spot: both analyze a single point in time. An order-form spec passes every such test while the product is broken, because the defect lives in history: 'cancel an order that already shipped' is only reachable as the third event in a sequence, and no single-input test can express it. Stateful features — orders, tickets, subscriptions, file uploads, playlist items — need a technique that models time: state transition testing.

The first artifact is a state diagram: states as nodes, events as labeled edges, optional guards ([qty > 0]) and actions (/ send confirmation) on the edges:

[Created] --submit--> [Paid] --ship--> [Shipped] --deliver--> [Delivered]
     [Created]/[Paid] --cancel--> [Cancelled]
[Shipped] --cancel--> ???   ← edge missing from the diagram = spec question or defect
[Delivered] --return--> [Refunding] --approve--> [Refunded]

Reading that ??? is the technique's interview moment: the diagram has a missing transition, and the tester's question — 'what happens if the customer cancels a shipped order?' — is a requirement defect found by construction, before a line of code implements the wrong default (most commonly: an exception stack trace, or worse, a silent success that marks a shipped parcel cancelled in the database).

The second discipline is choosing how much of the diagram to test. Full path enumeration is exponential (loops make it infinite), so standard coverage levels bound it:

  • 0-switch coverage (state coverage): every state is visited at least once — the minimum; finds unreachable states and dead ends.
  • 1-switch coverage (transition coverage): every legal transition is exercised once — the practical default for most suites; every edge in the diagram has a test.
  • n-switch coverage: every sequence of n+1 transitions is exercised; 2-switch (every ordered pair of consecutive transitions) catches sequence-dependent defects like cancel-after-ship and is affordable for the critical paths of payment and fulfillment flows.

1-switch coverage deserves emphasis because it is what people mean when they say 'we test all the transitions': each edge tested in isolation verifies the event works from its source state, but not that orderings behave — a feature can pass 1-switch and fail a 2-switch case where state A's residue affects state B's handling (refunding a partially-shipped order is a two-transition defect).

Invalid transitions are test cases, not omissions. For every state, events that are not legal there are as important as the legal ones: ship on a Cancelled order must be rejected with a defined error, not processed. The systematic move is a state × event matrix — rows are states, columns are events, each cell either names the expected next state or 'rejected with error X' — and requiring every cell to be filled turns the diagram into a complete contract. This matrix is also the automation blueprint: one parameterized test per row, feeding event sequences from a data table, runs the entire model in seconds.

Interview prompts for this topic are almost always practical: 'the app has draft/scheduled/published articles with comments — design tests.' Deliver the state list first (Draft, Scheduled, Published, plus Archived if the spec allows), then transitions with guards, then the invalid-event matrix, then state your coverage level and why (1-switch default, 2-switch on the destructive paths: publish→unpublish with live comments, delete-with-replies). That structure shows the interviewer the technique, not just a case list.

Choosing Between Tables and Transitions — and Composing Them

Both techniques model combinations; choosing wrongly costs a week of the wrong tests. The split is by defect family, and it can be stated as one question: does the feature's behavior depend on the simultaneous state of several conditions, or on the order in which events arrive?

Signal Technique
Behavior decided by yes/no condition combinations at one moment (pricing rules, permissions, eligibility) Decision table
Behavior depends on sequence and history (orders, tickets, uploads, subscriptions) State transitions
Rules with exceptions layered on exceptions ('free unless express unless member') Decision table — prose hides the interactions
Feature with a lifecycle and destructive operations State transitions + invalid-event matrix

Real features often need both, and the composition pattern is stable: model the lifecycle with states, then decision-table the logic inside each state. A subscription service illustrates it — the state model handles Trial → Active → PastDue → Cancelled with events (renew, payment-fail, cancel, restore), and inside the Active→PastDue transition a decision table governs the dunning logic: grace period × payment method × retry count × plan type → action (retry, notify, downgrade, suspend). Neither diagram alone is sufficient: the state model without the table cannot say what PastDue does; the table without the model cannot say when its rules run. Each artifact's test cases then target different bugs: the state suite finds sequence defects (restore after cancel is ignored), the table suite finds rule defects (grace period ignored for annual plans).

The senior-level question that closes the topic: where do these techniques end and defects still escape? Three honest limits. First, tables and diagrams cover the modeled logic; they say nothing about timing (what if the renewal job runs twice concurrently — now you need concurrency testing), data volume (dunning with 100,000 due invoices), or the UI's fidelity to the model (the API honors Cancelled but the screen still shows a Cancel button). Second, the model is only as good as the spec-reading behind it: a missing state is invisible forever — which is why the diagram review with product and support (support knows which state combinations users actually reach) is not optional. Third, state explosions in real systems (an order with five line items each in one of four states is 4^5 = 1,024 joint states) push you back toward risk-based sampling — cover the pairwise joint states for the critical path and state the exclusion.

For interviews, the durable takeaway to state plainly: decision tables and state transitions are specification instruments first, test generators second — they force ambiguity (a disputed cell, a missing edge) into the open while it is still a text edit. Candidates who describe finding a requirement defect by building the table, and name the coverage level they chose for the lifecycle suite, consistently read as practitioners. The next technique in this phase takes on the case these two deliberately leave alone — many-parameter configurations like browsers × OS × devices — in Pairwise Combination Testing.

Quiz

1. A rule set has 5 binary conditions. How many columns does the full decision table have before pruning, and what justifies removing a column?

Question 1 options

2. An order lifecycle is Created → Paid → Shipped → Delivered, with cancel allowed from Created and Paid. What does the missing cancel transition from Shipped tell the tester?

Question 2 options

3. What does 1-switch (transition) coverage guarantee that 0-switch (state) coverage does not?

Question 3 options

4. A subscription feature's dunning logic depends on grace period, payment method, retry count, and plan type, and the subscription itself moves Trial → Active → PastDue → Cancelled. What is the correct modeling approach?

Question 4 options

Flashcards

Question

The four passes of building a decision table.

Answer

(1) List conditions and their possible values; (2) enumerate combination columns (2^n for binary conditions); (3) prune — remove impossible combinations and merge duplicates whose actions are identical with irrelevant differing conditions; (4) write the expected action per surviving column with the product owner present, then link one test case per column.

Question

What is the greatest risk when using a decision table, and how do you control it?

Answer

Silent gaps: 16 columns written, a few tested implicitly, and partial coverage laundered as proof. Control: number every column, require a test ID or an explicit 'impossible/merged — justification' note per column, and treat the table as living spec — a rule change's blast radius is exactly the columns linked to it.

Question

Define 0-switch and 1-switch coverage, and when 2-switch earns its cost.

Answer

0-switch (state coverage): every state visited at least once — finds unreachable states. 1-switch (transition coverage): every legal edge exercised once — the default practical suite; every event verified from its source state. 2-switch: every ordered pair of consecutive transitions — use on critical/destructive paths where sequence residue matters (cancel-after-ship, refund after partial fulfillment).

Question

What is the state × event matrix and what does requiring every cell give you?

Answer

Rows are states, columns are events; each cell names the expected next state or 'rejected with error X'. Requiring every cell filled makes illegal transitions explicit test cases (ship on a Cancelled order must be rejected, not processed) and turns the diagram into a complete contract — also serving as a parameterized-automation blueprint (one test per row).

Question

Decision tables vs state transitions: the selection question and the composition pattern.

Answer

Selection: does behavior depend on simultaneous condition combinations (→ decision table) or on event order and history (→ state transitions)? Composition: model the lifecycle with states, then decision-table the logic inside each transition — the state suite finds sequence defects, the table suite finds rule defects. Neither alone covers the other's family.

Revision Notes

Key Takeaways

  • 1. Decision tables make combination coverage provable: enumerate, prune only impossible/duplicate columns, and require a test ID or justification per column
  • 2. A disputed action cell found while building the table is a requirement defect — the table is a specification instrument before it is a test generator
  • 3. State diagrams surface missing behaviors by construction: an absent edge forces the 'what happens if…' question while the spec is still an edit
  • 4. 1-switch verifies every transition in isolation; sequence-dependent defects need 2-switch on the critical paths, and illegal events need explicit rejection cases via the state × event matrix
  • 5. Compose the techniques for lifecycle features: states for the when, decision tables for the what — each catches a different defect family

Interview Tips

  • • "Design tests for a shipping-rule spec with four conditions." — say you would build a decision table: 16 combinations, prune impossible/duplicates, one test per column; mention that disputed cells go back to product as requirement defects
  • • "Cancel an already-shipped order — how would this escape normal testing?" — it is a sequence defect invisible to point-in-time techniques; a state diagram with the missing Shipped→cancel edge forces the specification of rejection behavior
  • • "Difference between 0-switch and 1-switch coverage?" — states visited vs edges exercised; add that edge tests in isolation can still miss order-dependent bugs, which is when you escalate to 2-switch on destructive paths
  • • "Decision table or state transition — which for feature X?" — answer with the selection question (simultaneous conditions vs event order) and then the composition pattern for lifecycle features; this shows judgment, not tool-recitation

Cheat Sheet

Decision Tables and State Transitions

Decision tables:

  • Full size = 2^n for n binary conditions (4 cond → 16 columns)
  • Prune only: impossible combinations · duplicate-action columns with irrelevant differing conditions
  • One test case per surviving column; concrete cell values from equivalence classes
  • Disputed cell = requirement defect found in review (bring product into column-4 pass)
  • Column discipline: every column gets a test ID or an 'impossible/merged + why' note

State transitions:

  • Diagram: states, events as edges, guards [cond], actions / do
  • Missing edge = spec question (cancel on Shipped?) — define reject-with-error or a return flow
  • Coverage: 0-switch (visit states) · 1-switch (every edge; default) · 2-switch (ordered pairs; critical paths only)
  • State × event matrix: every cell = next state or rejection error → invalid transitions become test cases

Composition: states model when rules run; a decision table inside a transition models what happens (dunning logic in Active→PastDue). Test different defect families: sequence vs rule.

Limits: timing/concurrency · volume (4^5 joint states → risk-based sampling) · UI fidelity to model (API rejects Cancelled but button still shows).

Continue Learning

Before You Start

Related Reading