UN

Unit Testing

Write and run isolated unit tests for every new function, method, or module

Details

Language / Topic
_UUniversal
Category
Testing

Rules

balanced
- Write unit tests for every new function or method immediately after implementation.
- Run the full unit test suite before committing — never push code with failing tests.
- Test one behavior per test case. Keep tests fast, isolated, and deterministic.
- Follow the Arrange-Act-Assert pattern: set up inputs, call the function, verify the output.
- Mock external dependencies (APIs, databases, file system) — unit tests validate your logic in isolation.
- Name tests descriptively: `should return empty array when no items match filter`.
- Test edge cases: empty inputs, nulls, boundary values, error conditions — not just the happy path.
- Run unit tests after every code change during development for fast feedback.