What is the test pyramid, when should you unit-test a method, and when should you mock external dependencies?
Short answer
Test pyramid: many unit tests (fast, cheap), fewer integration tests (real DB, HTTP), very few end-to-end tests (slow). Unit-test logic with branches.
3 points to say:
- Many unit, fewer integration, very few E2E.
- Business logic: unit tests; queries and mapping: integration tests.
- Don't mock what you don't own: wrap it behind an interface.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.