About

6.5 Decision Trees & Path-Derived Tests

Theory: Decision Trees & Path-Derived Tests

A decision table (6.2) lists every rule side by side, as if all conditions were checked at once. But many business rules are hierarchical: you ask one question first, and the next question depends on the answer. For those, a decision tree is the natural picture, and every path through it is a test case.

Decision Tree vs. Decision Table

Think of a doctor’s triage. The first question is “is the patient breathing?” Only if the answer is yes does the doctor ask about the pulse; nobody checks the blood pressure of someone who is not breathing. The questions form a tree, and each question is asked only where it matters.

Decision tableDecision tree
Shapeflat: one column per rulehierarchical: root, branches, leaves
Conditionsevery rule has an entry for every condition (1, 0 or X)a condition appears only in the branches where it matters
One rule / testone columnone root-to-leaf path
Best forindependent if-then conditionsdependent rules, where one answer decides which question comes next

A condition that a path never evaluates is simply not applicable on that path. That is the tree’s version of the table’s X.

The Procedure

  1. List the conditions and the possible outcomes.
  2. Place the broadest or most decisive condition at the root.
  3. Create one branch for every possible answer to that condition.
  4. Add a later condition only inside the branches where it matters.
  5. Continue until every reachable branch ends in an outcome leaf.
  6. Read each root-to-leaf path as one rule and one test case.
  7. Mark conditions the path never evaluates as not applicable, and use BVA to choose the concrete numeric values.

How to write the answer: draw the tree with labelled branches (yes/no on every edge) and an outcome on every leaf, then give a table with one test per path, writing “not applicable” for conditions the path never checks. Finish with the BVA values for every numeric threshold.

Example: A Discount Policy

Members receive 20% off orders of at least 1,000 with a valid coupon, 15% without one, and 5% below 1,000. Non-members receive 12% or 8% on orders of at least 1,000, with or without a valid coupon, and 0% below it.

Choose the hierarchy. Membership divides the rule set first, so it is the root. The order total is tested inside each membership branch. Coupon validity is tested only when the order reaches 1,000, because below the threshold it has no effect.

Diagram loads as you scroll.

The tree has six leaves, so six paths, so six tests:

PathMemberOrder totalCouponExpected discount
1Yes1,000 or moreValid20%
2Yes1,000 or moreInvalid / none15%
3YesBelow 1,000Not applicable5%
4No1,000 or moreValid12%
5No1,000 or moreInvalid / none8%
6NoBelow 1,000Not applicable0%

Compare with a decision table: three Boolean conditions give 23=82^3 = 8 full rules. The tree needs only 6, because in paths 3 and 6 the coupon is never asked about; each of those leaves stands for two table rules (coupon valid or not).

Add Boundary Values

The tree tells you which rule to test; BVA tells you which value. The threshold “at least 1,000” means 1,000 is the edge:

A programmer who wrote total > 1000 instead of total >= 1000 gives 5% at 1,000, and only the on-edge test catches it.

Common mistake: using a decision tree for behaviour that depends on history. A tree models a decision at one moment. If the result depends on previous orders, coupon history, time or the system’s state (for example “a coupon can be used only once”), a tree cannot show it; add state-transition testing.


Worked Examples

Exercise 1

How does a decision tree differ from a decision table? When would you choose a tree?

Show solution ↓
Solution

A decision table is flat: every rule is a column with an entry (1, 0 or X) for every condition. A decision tree is hierarchical: the most decisive condition is at the root, and each later condition is asked only in the branches where it matters. Each root-to-leaf path is one rule and one test case.

Choose a tree when the rules are dependent, when the answer to one question decides which question comes next (as in the discount policy, where the coupon matters only for orders of 1,000 or more). Choose a table when the conditions are independent if-then rules.

Exercise 2

Turn the six paths of the discount tree into concrete test cases, using simple values and the 1,000 threshold.

Show solution ↓
Solution

Use the boundary value 1,000 for the “at least 1,000” paths and 999 for the “below” paths:

TestMemberTotalCouponExpected
1yes1,000valid20%
2yes1,000invalid15%
3yes999(not applicable)5%
4no1,000valid12%
5no1,000invalid8%
6no999(not applicable)0%

Six tests, one per path, each with its expected discount. Because tests 1, 2, 4 and 5 sit exactly on the threshold, together with 3 and 6 just below it they also cover the BVA pair 1,000 / 999 for both membership branches.

Exercise 3

A member places an order of 999 with a valid coupon. What discount is expected, and which path is it? A developer’s code gives 20%. Is that a bug?

Show solution ↓
Solution

999 is below 1,000, so the order follows path 3 (member, below 1,000), where the coupon is not applicable. Expected discount: 5%.

The code gives 20%, so yes, it is a bug: the code applied the coupon below the threshold, probably by checking the coupon before (or without) the order total. This is exactly the kind of bug a value just below the boundary is meant to catch.

Exercise 4

A full decision table for the discount policy (member, total ≥ 1,000, valid coupon) would have how many rules? Why does the tree need fewer tests?

Show solution ↓
Solution

Three Boolean conditions give

23=8 rules.2^3 = 8 \text{ rules.}

The tree has only 6 leaves. Below 1,000 the coupon is never evaluated, so in each membership branch the “below 1,000” leaf stands for two table rules (coupon valid and coupon invalid) with the same outcome. That is 8−2=68 - 2 = 6 paths, so 6 tests. ✓ It is the tree’s version of a don’t-care X.

Exercise 5

The shop adds a rule: a coupon may be used only once per customer. Can you still test the policy with the decision tree alone? Explain.

Show solution ↓
Solution

No. A decision tree models a decision at one moment, from the inputs available right now. “Only once per customer” depends on history: whether this customer already used the coupon in an earlier order. The same inputs (member, 1,000, this coupon) must give 20% the first time and 15% the second time (when the coupon no longer counts as valid), which no single tree path can express.

The tester keeps the tree for the discount rules and adds state-transition testing for the coupon’s states (for example unused → used), with tests such as “use the coupon, then try to use it again → expect it to be rejected”.