Unit tests
Small tests for rules and calculations. They test behaviour through public functions, run in milliseconds, and give the same result every time.
- Required 3
- Recommended 2
Required
Test behaviour through the public interface
RequiredA 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
RequiredUnit tests never depend on the clock, random numbers or the network. They pass on any day, on any machine.
Keep unit tests fast
RequiredEach unit test runs in milliseconds, and the whole unit suite runs in seconds.
Recommended
Arrange, act and assert
RecommendedWrite each test in three parts. Set up the data, do one action, then check the result.
Give each test one reason to fail
RecommendedEach test checks one behaviour. When it fails, its name tells you what broke.
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.