---
title: "Test the edges and the errors · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/unit-tests/test-the-edges
updated: 2026-10-20
licence: "All rights reserved"
---

# Test the edges and the errors

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests)
- Rule: For every rule with a limit, test the values on both sides of it. For every input that can be rejected, test the rejection.
- How: List the limits of the rule, such as a minimum order, a date range or a maximum length. Test the last value inside each limit and the first value outside it. Add empty input, zero, negative numbers, missing fields and the largest allowed size. Test each error the function can raise, and check its type and message. Use the runner's table of cases, such as `test.each` or `pytest.mark.parametrize`, so each case names itself in the report.
- Check: Each limit in the code has a test at the limit and one past it. Moving a limit by one, such as `>=` to `>`, makes a test fail. [Mutation testing](https://agentwranglers.se/playbook/testing/test-quality/mutation-testing) finds this mechanically.

Example:

```js
// Free shipping from 50.00, in cents
test.each([
  [4999, 495],
  [5000, 0],
  [0, 495],
])('an order of %i cents pays %i cents shipping', (total, fee) => {
  expect(shippingFee(total)).toBe(fee);
});

test('a negative total is rejected', () => {
  expect(() => shippingFee(-1)).toThrow(RangeError);
});
```

```python
@pytest.mark.parametrize("total, fee", [(4999, 495), (5000, 0), (0, 495)])
def test_shipping_fee_at_the_free_shipping_limit(total, fee):
    assert shipping_fee(total) == fee

def test_a_negative_total_is_rejected():
    with pytest.raises(ValueError, match="total"):
        shipping_fee(-1)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/unit-tests/test-the-edges`.

- Previous: [Fake the clock and the network in unit tests](https://agentwranglers.se/playbook/testing/unit-tests/unit-deterministic)
- Next: [Arrange, act and assert](https://agentwranglers.se/playbook/testing/unit-tests/arrange-act-assert)
- [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests)
