unit-testing
Unit & Component Testing
Unit tests validate the smallest testable behaviors (functions, methods, classes, components) in isolation from slow or unreliable dependencies. Done well they are your fastest feedback loop and the safety net for refactoring.
Principles (F.I.R.S.T.)
Fast (milliseconds) · Isolated (no network, DB, clock, filesystem, randomness) · Repeatable (same result anywhere) · Self-validating (assert, do not eyeball) · Timely (written with or before the code, tdd-workflow).
- Arrange-Act-Assert: set up inputs, execute the unit, verify the outcome. One behavior per test; the name states the behavior.
- Test behavior, not implementation: assert on public outputs and observable effects so tests survive refactoring.
What to test
Business rules and calculations · branches and error paths · boundaries (test-design-techniques) · invariants (property-based-testing) · state transitions · input validation · idempotence · async success/failure/timeouts · component rendering and interaction (Testing Library: query by role/label, act like a user).