Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 60 ยท Test Design Techniques

Decision Table Testing

Learn decision table testing: list conditions, actions and rules, build a full table, collapse it with don't-care entries, and check an implementation against every rule.

Some requirements are not about ranges of values but about combinations of conditions. "Free delivery for members or for orders of 50 or more, and an extra 10 percent off if the customer has a coupon and the order is large enough." Reading a paragraph like that, it is easy to miss a combination. Writing it as a table makes every combination visible, and each row becomes a test.

That is decision table testing. A decision table lists all the combinations of conditions and the action the system should take for each. It is one of the best tools for finding gaps and contradictions in business rules, because an unclear combination shows up as an empty cell.

Real versus stand-in. Decision tables are a paper-and-spreadsheet technique applied to real business rules. The TryIt blocks are stand-ins: a short program that builds and collapses a table, and a small checkout function that plays the role of the system under test. Real tools also let you export a table into test cases, but the logic is the same.

Parts of a decision table

A decision table has four parts:

  • Conditions are the inputs or states that influence the outcome, such as "customer is a member".
  • Actions (or outcomes) are what the system does, such as "free delivery".
  • Rules are columns (or rows) that each describe one combination of condition values and the resulting actions.
  • Entries are the values in the cells: usually Y or N for conditions, and Y or N (or X) for actions.

Anatomy of a decision table

Conditions What can be true or false?
Actions What should the system do?
Rules One combination plus its result.

Each rule becomes at least one test case.

1 / 3

Building a full table

Take the delivery and discount rule:

  • Free delivery if the customer is a member or the order total is at least 50.
  • An extra 10 percent discount if the customer has a coupon and the order total is at least 50.

There are three conditions (member, total at least 50, coupon) and two actions (free delivery, 10 percent off).

With n yes/no conditions, a full table has 2 to the power of n rules, because each condition doubles the count. Three conditions give 8 rules, four give 16, ten give 1,024. That growth is the reason to collapse the table or to move to a smarter method such as Pairwise and Combinatorial Testing.

The stand-in below generates the full table from a function that encodes the rules. In real projects you derive the table from the requirement, not from code, because the table is the specification you test the code against. Here the function is a quick way to produce the expected values.

Collapsing a table

Look at the full table the stand-in prints. When the first condition is N and the second is N, the coupon makes no difference: both rules give no free delivery and no discount. These two can merge into one rule with a don't-care entry, written -, for the coupon.

The merge rule is strict. You may merge two rules only if:

  1. They give exactly the same actions, and
  2. They differ in exactly one condition, and that condition is Y in one rule and N in the other.

The merged rule shows - for that condition. Repeat until nothing can merge. A collapsed table has fewer columns but the same meaning. The risk is merging rules you should not have merged, which hides a case. Check each - by asking, "Is it really true that this condition makes no difference here?"

JS Building and collapsing a decision table

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The eight rules shrink to four. Read the result as a specification:

  • R1: a non-member with a small order gets nothing, whatever the coupon.
  • R2 and R3: any customer with a large order gets free delivery, and gets the 10 percent discount only with a coupon.
  • R4: a member with a small order gets free delivery and no discount.

Notice what the table makes plain: a member with a small order and a coupon gets no discount. If the business meant members to get coupon discounts on any order, the table reveals that the requirement and the intention disagree. That is exactly the kind of gap this technique is for.

Turning rules into tests

Each rule in the table becomes at least one test case. In a collapsed table a - entry means the value does not matter, so you can choose any value for it. Choosing different values in different tests, or testing each variation once, gives extra confidence at small cost.

For a table with numeric conditions like "total at least 50", combine this technique with Boundary Value Analysis: choose totals such as 49.99 and 50.00 so the threshold itself is tested. Decision tables decide which combinations to test; boundary analysis decides which values to use inside each condition.

Coverage for decision tables is measured as the number of rules covered by at least one test divided by the total number of rules. Aim for 100 percent of the rules in the table you wrote.

Checking an implementation against the table

Now use the collapsed table as the expected results and run a function against it. The checkout function below contains a planted defect: it lets members use a coupon even on small orders, while the table says the coupon needs a large order. Read the tenPercent line before you run it and predict which combination will fail.

The test loop walks all eight combinations, finds the matching rule in the table (the - entries match anything), and compares both actions.

JS Verifying a function against the table

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Exactly one combination fails: a member with a small order and a coupon. The implementation gives the discount, but the specification says no. That defect would have been easy to miss with a handful of ad hoc tests, since six of the eight combinations pass. Now decide which side is wrong: the table or the code. That is a question to take back to the business, and it is a good outcome of the exercise.

Fix the code by replacing the tenPercent line with hasCoupon && total >= 50, and run it again to see all eight pass.

Extended-entry tables

Sometimes a condition has more than two values, such as customer level (bronze, silver, gold). In an extended-entry table the cell holds the value itself instead of Y or N. You can always convert it to limited-entry form by splitting the condition into several yes/no conditions ("is gold", "is silver"), but then some combinations become impossible, and you should mark and remove them with a note rather than leave unexplained gaps.

When to use decision tables

Decision tables fit best when:

  • Behavior depends on several conditions together, as in pricing, eligibility, approval and permission rules.
  • The requirement is written as a long paragraph of "if" and "unless".
  • You suspect conflicts or missing cases in the rules.

They fit poorly when behavior depends on the order of events or on remembered history. For that, use State Transition Testing.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A decision table has 4 yes/no conditions. How many rules does the full table have?

    Each yes/no condition doubles the count, so 4 conditions give 2 x 2 x 2 x 2 = 16 rules.
  2. 2. When may two rules be merged into one with a '-' entry?

    Merging is safe only when one condition flips and the actions stay the same. Otherwise the table would lose information.
  3. 3. What does a '-' entry in a condition cell mean?

    A dash is a don't-care entry: both Y and N lead to the same actions for that rule.
  4. 4. What is the best use of decision table testing?

    Decision tables are made for combinations of conditions. Ranges call for boundary analysis and ordered events for state transition testing.

Summary

  • A decision table lists conditions, actions and rules, so every combination of conditions has a defined result.
  • A full table with n yes/no conditions has 2^n rules; collapse rules that differ in one condition and give identical actions, using - for don't-care.
  • Each rule becomes at least one test, and coverage is the share of rules exercised.
  • Empty or conflicting cells reveal gaps and contradictions in the requirements before any code runs.
  • Combine decision tables (which combinations) with boundary analysis (which values) for numeric conditions.

Next: State Transition Testing.