Decision table: every combination

level 1 · 15 min · decision table testing

Some rules depend on more than one condition at once: “club member” and “has a coupon”, for example. Two yes-or-no conditions give four combinations, and each can have its own result.

A decision table puts the conditions in columns and one combination per row, with the expected result beside it. It does two things: it shows whether any combination was left without a rule, and it gives a ready list of tests, one per row.

Rule of thumb. List the combinations of conditions in a table and write one test per row. With two conditions that is four rows; with three, eight.

Explore the rule

The store computes the discount with discountPercent(isMember, hasCoupon). Change the conditions and see which row of the table applies.

discountPercent(false, false) → 0
Discount decision table
MemberCouponDiscount
yesyes15%
yesno10%
noyes5%
nono0%

Exercise: write the tests

Your tests must pass on the correct code and fail on the 4 planted bugs.

discountPercent(isMember, hasCoupon) combines two conditions. The rules for each combination are in the contract.

Write one test per combination. A bug that breaks a single row stays hidden unless a test lands exactly on that row.

/**
 * Discount percentage for an order.
 * - Member with a coupon: 15.
 * - Member without a coupon: 10.
 * - Non-member with a coupon: 5.
 * - Non-member without a coupon: 0.
 * @param {boolean} isMember
 * @param {boolean} hasCoupon
 * @returns {number}
 */
function discountPercent(isMember, hasCoupon)

Coverage radar: ranges and limits your tests already touch

  • Member: yes · coupon: yes → 15%: covered
  • Member: yes · coupon: no → 10%: not yet
  • Member: no · coupon: yes → 5%: not yet
  • Member: no · coupon: no → 0%: not yet

Your tests

0 of 4 bugs detected

  • Bug 1: hidden
  • Bug 2: hidden
  • Bug 3: hidden
  • Bug 4: hidden

References

  • ISTQB® Certified Tester Foundation Level v4.0, section 4.2.3, Decision Table Testing. © ISTQB®.