---
title: "Test rules with several conditions as a · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/unit-tests/decision-tables
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Test rules with several conditions as a table

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- Level: Recommended
- Chapter: [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests)
- Rule: When a result depends on two or more conditions, list every combination in a table with its expected result. Run each row as a test.
- How: Name the conditions, such as member or guest, a coupon or none, and an order above or below the free shipping limit. Write one row per combination, with the result the business expects. Ask the owner of the rule to read the table, because a missing row is where bugs hide. Merge rows only where a condition makes no difference, and name the ignored condition in the row. For conditions with a limit, also test the limit itself, as [Test the edges and the errors](https://agentwranglers.se/playbook/testing/unit-tests/test-the-edges) says. Roles and actions follow the same idea in [Test every role against every action](https://agentwranglers.se/playbook/accounts/roles-and-permissions/permission-matrix-test).
- Check: Multiply the number of values of each condition. The table has that many rows, or merged rows that name the conditions they ignore. Change the result for one combination in the code, and only that row's test fails.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Python example

```python
import pytest

# member, coupon, order total in cents, expected shipping fee in cents
SHIPPING = [
    (True,  None,       4999, 0),
    (True,  None,       5000, 0),
    (False, None,       4999, 495),
    (False, None,       5000, 0),
    (False, "FREESHIP", 4999, 0),
    (False, "FREESHIP", 5000, 0),
    (True,  "FREESHIP", 4999, 0),
    (True,  "FREESHIP", 5000, 0),
]

@pytest.mark.parametrize("member,coupon,total,fee", SHIPPING)
def test_shipping_fee(member, coupon, total, fee):
    assert shipping_fee(member=member, coupon=coupon, total=total) == fee
```

### JavaScript example

```js
import { expect, test } from 'vitest';

test.each([
  { member: true, coupon: null, total: 4999, fee: 0 },
  { member: true, coupon: null, total: 5000, fee: 0 },
  { member: false, coupon: null, total: 4999, fee: 495 },
  { member: false, coupon: null, total: 5000, fee: 0 },
  { member: false, coupon: 'FREESHIP', total: 4999, fee: 0 },
  { member: false, coupon: 'FREESHIP', total: 5000, fee: 0 },
  { member: true, coupon: 'FREESHIP', total: 4999, fee: 0 },
  { member: true, coupon: 'FREESHIP', total: 5000, fee: 0 },
])('member $member, coupon $coupon, total $total pays $fee', ({ member, coupon, total, fee }) => {
  expect(shippingFee({ member, coupon, total })).toBe(fee);
});
```

## Related rules

- [Test the edges and the errors](https://agentwranglers.se/playbook/testing/unit-tests/test-the-edges) in Testing
- [Test every role against every action](https://agentwranglers.se/playbook/accounts/roles-and-permissions/permission-matrix-test) in Accounts

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/testing/unit-tests/decision-tables">Agent Wranglers testing playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Check rules that hold for any input with property tests](https://agentwranglers.se/playbook/testing/unit-tests/property-tests)
- [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests)
