Unit vs integration vs E2E tests?
Understand the concept
Unit tests check a small piece of logic, integration tests verify collaborating components, and E2E tests exercise a complete user or API flow. They catch different classes of failure and have different setup and execution costs. A balanced strategy puts detailed business-rule checks near the unit level and preserves real integration coverage where mocks would hide bugs.
Important ideas
-
Unit: one function or small module in isolation.
-
Integration: real components together, such as a service and database.
-
E2E: a full user flow; keep a focused set for critical behavior.
-
Use real database tests for constraints and rollback behavior; a mocked repository cannot prove these work.
Example — a focused unit test:
function canReserve(stock, quantity) {
return Number.isInteger(quantity) && quantity > 0 && stock >= quantity;
}
test('rejects a negative reservation quantity', () => {
expect(canReserve(5, -2)).toBe(false);
});- This checks validation only. A separate real-database integration test is needed to prove concurrent reservations cannot oversell.
Can you explain it without the notes?
Unit vs integration vs E2E tests?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Unit tests check a small piece of logic, integration tests verify collaborating components, and E2E tests exercise a complete user or API flow. They catch different classes of failure and have different setup and execution costs. A balanced strategy puts detailed business-rule checks near the unit level and preserves real integration coverage where mocks would hide bugs.
Turn this concept into a clear answer.
- Explain what a test deliberately includes and excludes, and why that boundary is useful.
Keep connecting the ideas.
Next lesson: What are Jest, React Testing Library and Supertest?Adapted from 09_TESTING_GIT_DOCKER_CLOUD.md · “Unit vs integration vs E2E tests?”. Examples are study fragments; framework behavior can depend on your version.