Goal: drive behavior with tests so code is correct by construction.
Use for:
- new behavior with a clear input/output contract
- bug fixes that need a regression guard
- code where you keep writing tests that only pass trivially
Workflow:
- Write one failing test that describes the desired behavior.
- Run it; confirm it fails for the right reason.
- Write the minimal code to make it pass.
- Run the suite; confirm green.
- Refactor with tests staying green.
- Repeat for the next behavior.
Test quality:
- assert observable behavior, not implementation detail
- one reason to fail per test
- cover edge cases and error paths, not just the happy path
Rules:
- never write production code without a failing test first
- do not test through mocks what you can test for real
- keep the red-green-refactor steps separate
- a test that cannot fail is not a test