---
title: "Unit tests · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/unit-tests
updated: 2026-10-20
licence: "All rights reserved"
---

# Unit tests

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

> Small tests for rules and calculations. They test behaviour through public functions, run in milliseconds, and give the same result every time.

**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`.

## Required

- [Test behaviour through the public interface](https://agentwranglers.se/playbook/testing/unit-tests/unit-behaviour): A unit test calls a function or class the way callers do, and checks what it returns or changes.
- [Fake the clock and the network in unit tests](https://agentwranglers.se/playbook/testing/unit-tests/unit-deterministic): Unit tests never depend on the clock, random numbers or the network. They pass on any day, on any machine.
- [Test the edges and the errors](https://agentwranglers.se/playbook/testing/unit-tests/test-the-edges): For every rule with a limit, test the values on both sides of it. For every input that can be rejected, test the rejection.

## Recommended

- [Arrange, act and assert](https://agentwranglers.se/playbook/testing/unit-tests/arrange-act-assert): Write each test in three parts. Set up the data, do one action, then check the result.
- [Give each test one reason to fail](https://agentwranglers.se/playbook/testing/unit-tests/one-reason-to-fail): Each test checks one behaviour. When it fails, its name tells you what broke.
- [Keep unit tests fast](https://agentwranglers.se/playbook/testing/unit-tests/fast-unit-tests): Each unit test runs in milliseconds, and the whole unit suite runs in seconds.

- Previous: [Test strategy](https://agentwranglers.se/playbook/testing/test-strategy)
- Next: [Integration and contract tests](https://agentwranglers.se/playbook/testing/integration-and-contract-tests)
- [All chapters](https://agentwranglers.se/playbook/testing)
