Unit — single component. Integration — component interaction. E2E — complete flow.
Unit Testing:
Unit Test:
test("add", () => {
expect(add(1, 2)).toBe(3);
});
(Single function)
Integration Testing:
Integration Test:
test("API + DB", () => {
const user = createUser({name: "John"});
expect(user.id).toBeDefined();
});
(Components together)
End-to-End Testing:
E2E Test:
Login → Add to cart → Checkout
(Complete flow)
Test Pyramid: Many unit → fewer integration → few E2E.