---
title: "Unit test the tricky parts · Agent Wranglers"
url: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/unit-tests-for-the-tricky-parts
updated: 2026-10-20
licence: "All rights reserved"
---

# Unit test the tricky parts

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

- Level: Required
- Chapter: [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy)
- Rule: Test logic that can break silently on its own, without a network, a database or a browser.
- How: Keep small, fast tests next to the code for anything with branches or calculations, such as parsing, prices and dates. Use the language's usual runner, such as `node --test`, pytest or PHPUnit. Run them before every build. For more depth, see [the testing playbook](https://agentwranglers.se/playbook/testing/unit-tests/unit-behaviour).
- Check: The tests run in seconds, in the full check before every deploy. Break the logic on purpose, and a test fails.

Example:

```js
// date.test.js, run with: node --test
import test from 'node:test';
import assert from 'node:assert/strict';
import { formatDate } from './date.js';

test('formats a date for people', () => {
  assert.equal(formatDate('2026-10-20'), '20 October 2026');
});
```

```python
# test_dates.py, run with: pytest
from dates import format_date

def test_formats_a_date_for_people():
    assert format_date("2026-10-20") == "20 October 2026"
```

**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 engineering playbook: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/unit-tests-for-the-tricky-parts`.

- Next: [Run the tests inside the container build](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/container-build-gated-by-tests)
- [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy)
