𝗪𝗵𝗮𝘁 𝗧𝗲𝘀𝘁 𝗚𝗼𝗲𝘀 𝗪𝗵𝗲𝗿𝗲?
Teams often ask the right questions at the wrong layer.
A unit test for a full checkout is too high. A BDD test for a regex is too low. Both tests pass, but neither does its job.
This makes your test suite slow and fragile. You add more tests to fix it. The suite slows down more. Confidence does not improve.
Do not focus on the number of tests. Put each test in the layer where it gives the most confidence for the lowest cost.
Use these four layers:
- Unit tests: Check logic in isolation.
- Integration tests: Check if components work together.
- End-to-end tests: Check real user workflows.
- BDD scenarios: Check if behavior matches the business agreement.
Pick the cheapest layer to answer your question.
- Internal logic, math, or validation? Use unit tests.
- API calls or database queries? Use integration tests.
- Critical flows like checkout or signup? Use E2E.
- Business rules for stakeholders? Use BDD.
Avoid these mistakes:
- Too many E2E tests. You pay a high price for weak signals.
- Fake integration. You mock everything in unit tests.
- Technical detail in BDD. Stakeholders do not care about cache loops.
A healthy suite does not repeat the same check in every layer. Place each assertion where it gives the most signal.
Write each test where it earns its cost.
Source: https://dev.to/krinosystems/what-test-goes-where-a-practical-guide-to-test-layer-decisions-3079