Introduction
Testing a single unit (method/class) in isolation from other components.
- Ensure the smallest code piece works correctly.
- Catch bugs early.
- Document expected behavior.
Testing the real logic correct or not
- Business rules
- Calculations
- Conditions
- Branching logic
Characteristics
- Isolated → no DB, network, file I/O.
- mocks for all external calls (DB, APIs, file system)
- Not testing spring wiring
- Fast → milliseconds, can run hundreds of tests quickly.
- Deterministic → same input → same output.
- Focused → one scenario/assertion per test.
Annotations