QA Interview Hub · Knowledge base · Quizzes · Українська

QA Fundamentals › Test design techniques

Decision table and state transition

A decision table fits when the current combination of conditions decides the result, while state transition fits when state and event history decide it. A discount by status and amount is a decision table, and cancelling an order by state is a state diagram. A table grows as 2 to the power of n, so it is collapsed only where independence is confirmed, and thresholds get boundary checks.

QA Fundamentals · Test design techniques

A discount depends on two conditions, an order status on the history of events. Which technique for which?

The two techniques in this chapter are often confused, because both draw tables and both are useful for business logic. But they answer different questions. A decision table answers what must happen for this combination of conditions now. State transition answers what must happen when an event arrives at an object that already has a history. This lesson is about telling them apart, counting the size of a table and where they work together.

How it works and why

A decision table fits when the result is determined by the current values of several conditions, and the order in which they became so does not matter. A discount is like that: VIP and an amount above 1,000 give the result regardless of what was before. State transition fits when the same event gives a different result depending on the state, and the state depends on earlier events. "Cancel" acts differently for a new order and for a delivered one.

Which technique to take

Decision table

Question: what is the result for this combination of conditions? Examples: discounts, tariffs, access rights, decline conditions. Unit of checking: a column (rule).

State transition

Question: what is allowed in this state? Examples: an order, a payment, an account, a ticket. Unit of checking: a transition (state + event).

Figure 1. If the result depends on history, you need states. If only on current conditions, a table.

Example: a discount and the size of the table

A discount depends on two conditions: whether the customer is VIP and whether the order amount is above 1,000 UAH. There are two conditions, so the full table has four rules, and each is checked separately:

A decision table for a discount

Condition / rule1234
Customer is VIPYesYesNoNo
Amount above 1,000YesNoYesNo
Discount15%10%5%0%
Figure 2. Four combinations, four different results. This is where you see that no rule is lost.

The table immediately raises a question that was not in the requirements: what about an amount of exactly 1,000? That is already the boundary of a condition, so it is checked with boundary value analysis: 1,000 and 1,000.01 (or 999.99, 1,000, 1,000.01 for 3-value). This is how the techniques combine: the table gives combinations, boundaries refine the threshold conditions.

The size of the table grows as 2n: two conditions give 4 rules, three 8, four 16, five 32, ten 1,024. So the table is collapsed by merging rules where a condition does not affect the result, and for large sets of conditions it is combined with pairwise or rules are chosen by risk.

State transition for an order

An order goes New → Paid → Shipped → Delivered and can move to Cancelled. For it we test all valid transitions and check that invalid ones are forbidden: a delivered order cannot be cancelled, nor a cancelled one paid.

When do both techniques work together? Often the state itself becomes a condition in a table. A refund depends on the order state and on the payment method: in Paid we refund fully, in Shipped minus delivery, in Delivered only through the return procedure. Here the state is one condition, the payment method another, and the result comes from the table.

Limits and alternatives

  • A table knows nothing about order. If a rule depends on a sequence ("the third failed attempt locks the account"), that is states with a counter.
  • A state diagram does not show combinations of conditions inside one transition. If permission depends on several conditions, a table is built alongside.
  • Both techniques need unambiguous requirements. The gaps they reveal are part of the benefit.

Typical mistakes

  • Taking a decision table for a history of events. A table does not reflect how the object got here.
  • Taking state transition for a combination of conditions. The diagram sprawls for nothing when four columns would do.
  • Not checking the boundaries of conditions. "Above 1,000" without checking 1,000 leaves the most common error.
  • Not counting 2n in advance. A table of six conditions with 64 columns will not be read by anyone.

Check yourself

Suppose the requirements change: a VIP gets 10% for any amount. How does that show in the table?

Answer

For a VIP the condition "amount above 1,000" has no effect, so the cell has "—", and the rules "VIP and a large amount", "VIP and a small amount" merge into one. For each pair of rules this should be confirmed by the requirements.

Which example needs a state diagram instead of a table: a tariff by number of users or locking an account after three failed logins?

Answer

Locking. The result depends on history (a counter of failed attempts), not on a current combination of conditions. The tariff is determined by current values, and a table is enough for it.

How do you link a decision table and BVA in the discount example?

Answer

The table gives combinations of VIP / not VIP and the amount above / below the threshold. The threshold "above 1,000" is a boundary, so 1,000 and 1,000.01 (and 999.99 for 3-value) are added to check that exactly 1,000 is handled according to the requirements.

In an interview. Junior: I use a decision table when the result depends on a combination of conditions, for example a discount by status and amount. State transition when an object has states, like an order: I check valid and invalid transitions. Middle/Senior: I take a table for combinations of conditions and a state diagram for the history of events, and when a transition depends on several conditions I combine them. I check the thresholds of conditions with boundaries, count the size of the table in advance and collapse it only where independence is confirmed by the requirements.

More articles in this chapter