QA AND TEST AUTOMATION · PART 1 · MANUAL TESTING, PROPERLY · TECHNIQUE · 11 OF 112

Decision Table Testing Explained With Examples

How to test rules that combine: find the conditions and actions, count the rules (2 to the power of n), fill and merge the table, mark impossible rules, and turn each rule into a test case. Worked on the ShopRung coupon and free-shipping rules with real values, a JUnit 5 parameterized test, and the mistakes interviewers probe.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 16

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Conditions and actions
  • 2^n rules
  • merge with dashes
  • mark impossible rules
  • one test per rule

Notes

The problem

Look at the coupon box in the ShopRung cart. Three requirements touch it. An unknown code is refused. WELCOME15 has expired and must be refused with its own message. SAVE10 only works from a subtotal of fifty dollars. Each rule is simple on its own. The hard questions are about combinations. What happens when a code is real, but the cart is too small? Testing each rule once, in isolation, will not answer that.

One coupon box, three rules
  • PRICE-7 unknown code: "No coupon called <CODE>"
  • PRICE-5 WELCOME15 expired: "This coupon has expired"
  • PRICE-3 SAVE10 needs a subtotal of $50.00 or more
  • which message wins when two rules are true at once?

The idea

A decision table is a grid. Conditions go in the top rows, things that are true or false, like the email has an account. Actions go in the bottom rows, the things the system does. Each column is a rule: one combination of conditions and the actions it must cause. Here is ShopRung login. Two conditions give four rules. Only the first logs you in. The other three show the same message, which is exactly what rule account six asks for.

A tiny table: login (ACC-6)
                    R1  R2  R3  R4
email has account   Y   Y   N   N
password correct    Y   N   Y   N
-------------------------------
log in              X
show "Email or
  password is wrong"     X   X   X

2 conditions = 4 rules

The vocabulary

A few words you will hear in interviews. A condition is an input or a state that is either true or false. An action is something the system does. A rule is one column. In the cells you write Y for true and N for false, and a dash when that condition does not matter for this rule. An X marks the actions that happen. Tables with only Y and N are called limited entry. When a cell holds a value or a range instead, it is extended entry.

Words you will hear
  • condition: an input or state that is true or false
  • action: what the system does
  • rule: one column, one combination + its actions
  • Y / N: true / false
  • : "does not matter here"
  • X : this action happens
  • extended entry: values such as "< $50" instead of Y/N

Step 1 · Conditions

Step one. Read the requirements and turn each decision into a yes or no question. For the coupon box there are three. Does the code exist? Has it expired? Is the subtotal at least the coupon's minimum? The actions are: take the discount off, and show a message. Notice what is not a condition. Lowercase save ten works the same as uppercase, because rule price two says codes are not case sensitive. That is a partition to test, not a new row.

From PRICE-3, 5, 7
  • conditions C1 the code exists C2 the code has expired C3 subtotal >= its minimum
  • actions A1 take the discount off A2 show the right message
  • codes are not case-sensitive (PRICE-2): save10 = SAVE10

Step 2 · Count rules

Step two. Count the rules. Each yes or no condition doubles the number of combinations, so three conditions give two times two times two, which is eight. Write all eight columns in a fixed pattern, so you cannot miss one: the first row flips every four columns, the next every two, the last every column. Then fill in the actions for each rule. Only rule three, a real code that has not expired with a big enough cart, gives the discount.

The full table: 2^3 = 8
             R1 R2 R3 R4 R5 R6 R7 R8
exists       Y  Y  Y  Y  N  N  N  N
expired      Y  Y  N  N  Y  Y  N  N
enough       Y  N  Y  N  Y  N  Y  N
-----------------------------------
discount           X
expired msg  X  X
needs $ msg           X
unknown msg              X  X  X  X

Step 3 · Merge

Step three. Merge. Look at the four columns where the code does not exist. Expired or not, enough or not, the answer is always no coupon called that code. So those four become one rule with dashes. The same happens for an expired code: the subtotal does not change the answer. Eight rules become four. Only merge columns whose actions are identical. And write down the order of checks you assumed, because the requirements rarely say which message wins.

Collapsed: 8 rules → 4
              R1    R2    R3    R4
exists        N     Y     Y     Y
expired       -     Y     N     N
enough        -     -     N     Y
------------------------------------
action      unknown expired needs  10%
            msg     msg    $50   off

merge only when every merged
column has the same actions

Step 4 · Test cases

Step four. Turn each rule into a test case with real data. Rule one, the code SAVE20 on a sixty dollar cart, four green mugs. Expect no coupon called SAVE20. Rule two, welcome fifteen in lowercase on the same cart. Expect this coupon has expired, and you have checked case too. Rule three, SAVE10 with one hoodie at forty nine ninety nine. Expect the needs fifty dollars message. Rule four, four notebooks at exactly fifty dollars. Expect five dollars off.

Four rules, four tests
R1 SAVE20 at $60.00
   → "No coupon called SAVE20"
R2 welcome15 at $60.00
   → "This coupon has expired"
R3 SAVE10 at $49.99 (1 hoodie)
   → "...at least $50.00"
R4 SAVE10 at $50.00 (4 notebooks)
   → $5.00 off

$60.00 = 4 Green Build Mugs

Run them

Now run them. In the shop you type the code and read the message. Through the API you can check more. Rule two returns status code four hundred, with the error coupon not applicable and the message this coupon has expired. Rule one, the unknown code, returns four hundred and four with unknown coupon. Rule four returns the cart with a discount of five dollars. One table gave you four tests, and each one checks a different branch of the code.

Rule 2 through the API
POST /api/cart/coupon
{"code": "welcome15"}

HTTP/1.1 400 Bad Request
{"error": "coupon_not_applicable",
 "message": "This coupon has
   expired"}

R1 SAVE20 → 404 unknown_coupon

Impossible rules

A second table, for SAVE10 and shipping. Rule price nine says shipping is free when the subtotal after the discount is seventy five dollars or more. Two conditions: is the subtotal at least fifty, and is the amount after the discount at least seventy five. Look at rule two. If the subtotal is under fifty, there is no discount, so the amount after it is also under fifty. It can never reach seventy five. That rule is infeasible. Mark it, and do not try to test it.

SAVE10 and free shipping
                  R1   R2   R3   R4
subtotal >= $50   N    N    Y    Y
after 10% >= $75  N    Y    N    Y
----------------------------------
take 10% off                X    X
shipping $4.99    X         X
shipping free                    X

R2: impossible. No discount,
so "after" is under $50 too

The surprise

Now the feasible rules with real carts. A thirty dollar cart is refused, pays shipping, total thirty four ninety nine. A keyboard plus a sticker pack is seventy nine ninety nine. Without a coupon, shipping is free. With SAVE10 the customer saves eight dollars, drops to seventy one ninety nine, and now pays four ninety nine shipping. Total seventy six ninety eight. That is correct by the rule, but surprising. Decision tables find exactly these questions to raise with the product owner.

Real carts, real totals
R1 $30.00, SAVE10 refused
   shipping $4.99   total $34.99
R3 $79.99 (keyboard + stickers)
   -$8.00 = $71.99, ship $4.99
   total $76.98
   no coupon: free ship, $79.99
R4 $100.00 (8 notebooks)
   -$10.00 = $90.00, free ship
   total $90.00

Automate the table

A decision table maps straight onto a parameterized test. In JUnit five, each rule becomes one row of a CSV source: the code, the subtotal in cents, and the expected result. A small helper resets the shop, builds a cart worth that subtotal, posts the code and returns what happened. The name attribute prints rule one, rule two and so on in the report, so a failure points straight back at a column in your table. Add a rule, add a row.

JUnit 5
@ParameterizedTest(name = "rule {index}")
@CsvSource({
  "SAVE20,    6000, unknown_coupon",
  "welcome15, 6000, coupon_not_applicable",
  "SAVE10,    4999, coupon_not_applicable",
  "SAVE10,    5000, applied" })
void couponRule(String code, int cents,
                String expected) {
  assertEquals(expected,
      applyCoupon(code, cents));
}

Rules of thumb

Some rules of thumb. The table doubles with every condition. Four conditions give sixteen rules, ten give over a thousand. So once you pass four or five conditions, split the decision into smaller tables, for example one for which coupon applies and one for shipping. Merge with dashes, then recount to be sure no combination vanished. And measure decision table coverage as the rules you tested divided by the rules that are feasible. Aim for all of them.

Rules of thumb
  • conditions → full rules 2 → 4 3 → 8 4 → 16 5 → 32 10 → 1,024
  • over 4 or 5 conditions: split into smaller tables
  • merge with dashes, then check no rule was lost
  • coverage = rules tested / feasible rules

Common mistakes

The common mistakes. Testing each rule on its own and never the combinations, which is the whole point of the table. Merging columns whose actions are not the same, which quietly deletes a test. Spending an hour on an impossible combination and then logging it as a bug. Writing rules with no concrete values, so nobody can tell whether the test passed. And not asking which message wins when two rules clash. That last one is a requirement gap, and finding it early is a win.

Common mistakes
  • testing each rule alone, never the combinations
  • merging columns whose actions differ
  • testing an impossible rule, then logging a "bug"
  • no concrete values, so the test cannot fail clearly
  • not asking which message wins when two rules clash

Say it like this

The interview question is usually: how would you test a feature with several business rules? Say this. I list the conditions and the actions from the specification. Three yes or no conditions give eight rules. I merge columns that have the same outcome using dashes, mark any combinations that cannot happen, and write one test case per remaining rule with concrete data. For a coupon box, that came to four tests, and it also exposed a gap: the spec never said which message wins.

In the interview
  • "I list the conditions and actions from the spec. Three yes/no conditions give 8 rules. I merge columns with the same outcome using dashes, mark infeasible ones, and write one test per remaining rule. For a coupon box that was 4 tests."

Interview questions

Q1What is decision table testing?

A black-box technique for business rules that combine. You list the conditions and the actions, write one column (rule) for each combination of conditions, and design one test per feasible rule so every combination is exercised on purpose.

Q2How many rules does a decision table with 4 yes/no conditions have?

Two to the power four, which is 16 rules in the full table. Merging columns with identical actions and removing infeasible combinations usually leaves fewer rules to test.

Q3What does a dash mean in a decision table?

It means the condition does not affect the outcome for that rule, so the column stands for several merged combinations. You should only merge columns whose actions are exactly the same.

Q4What is an infeasible rule? Give an example.

A combination of conditions that cannot occur. With SAVE10, a subtotal under $50.00 gets no discount, so the amount after the discount cannot be $75.00 or more; that column is marked infeasible and not tested.

Q5How do you measure decision table coverage?

The number of feasible rules exercised by at least one test divided by the total number of feasible rules, usually as a percentage. Full coverage means every feasible column has a test.

Q6When would you choose a decision table over equivalence partitioning?

When the outcome depends on several conditions together rather than on one field. Partitioning and boundaries choose good values for each input; a decision table makes sure every combination of conditions that leads to a different outcome is tested.

Q7Your decision table has 9 conditions. What do you do?

Split it into smaller tables along natural lines, such as eligibility and pricing, merge rules with the same actions, and drop infeasible combinations. If many inputs are independent, use pairwise testing for those instead of the full product.

Q8How would you automate a decision table?

As a parameterized test, for example JUnit 5 @ParameterizedTest with @CsvSource or pytest.mark.parametrize, with one data row per rule holding the inputs and the expected outcome, named so a failure points back to the rule.