Unit Tests¶
Validate the smallest parts of the codebase independently, without external dependencies.
Focus¶
- Business logic
- Utility functions
- Domain behaviour
- Individual transformations
Characteristics¶
- Fast — should run in milliseconds
- Isolated — no database, no network, no filesystem
- Repeatable — same result every time
- Focused — one behaviour per test
Guidance¶
- Mock external dependencies at boundaries (the HTTP call, the API client), using the real response shape
- No network, no credentials, no warehouse: a unit test runs on a fresh laptop with nothing configured
- Isolate the environment: an autouse fixture clears the environment variables the code reads, so a developer's shell can't change the result
- Every bug fix comes with a test that fails without the fix
- Use
parametrizeinstead of copy-pasted tests; keep fixtures in theconftest.pyclosest to the tests that use them - Test behaviour, not implementation
- Keep tests small and named clearly
- Automate on every PR in CI
Data-Specific Examples¶
- Python helper functions
- dbt schema tests for transformations, data types, column existence
- Individual transformation logic