---
applyTo: "**/*.test.*,**/*.spec.*,**/test_*.py,**/*_test.go,tests/**"
description: How to write and change tests
---

# Test files

## Structure
- One behavior per test; name it as a sentence ("returns 404 when the order is missing").
- Arrange / act / assert with a blank line between sections.
- Use table-driven or parametrized tests for input variations instead of copy-paste.
- Build test data with small factories/builders; only set the fields that matter to the test.

## Determinism
- No real network, wall-clock time, or unseeded randomness. Fake the clock, seed RNGs, stub HTTP at the boundary.
- Tests must pass in any order and in parallel; clean up files, env vars, and DB rows.
- No fixed sleeps; wait on a condition or use fake timers.

## What to assert
- Assert on observable behavior (return values, HTTP responses, rendered text, DB state), not private internals or call counts unless the call is the behavior.
- Each test has at least one meaningful assertion; avoid giant snapshots.

## Never
- Never delete, skip, or loosen a failing test to make CI green, or change expected values to whatever the code returns now. If you believe the test is wrong, explain why in the PR.
- Never commit focused tests (`.only`, `fit`, `-run` hacks).
