Frontend Testing: Unit vs Integration vs E2E (What Interviewers Want)
A deep, interview-ready guide to frontend testing: what to test, unit vs integration vs e2e tradeoffs, reliable patterns, and common anti-patterns.
On this page
Testing is often the difference between “can build features” and “can ship reliable products”.
Interviews test whether you can choose the right test type and write maintainable tests.
30‑second interview answer
Use a testing pyramid mindset: unit tests for pure logic, integration tests for component + behavior together, and E2E for critical user flows. Favor tests that are reliable and user-centric (test outcomes, not implementation). Mock only what you must; the goal is confidence with minimal maintenance.
Key points
- Unit = fast and narrow.
- Integration = higher confidence for UI behavior.
- E2E = slowest but validates real flows.
- Avoid brittle tests tied to internal implementation.
1) The three test layers
Unit tests
- small scope
- fast
- mock dependencies
Integration tests
- test multiple parts together
- closer to real behavior
- fewer mocks
End-to-end (E2E)
- run the app like a user
- slowest but highest confidence
- catches integration issues
2) What to test (high ROI)
- critical user flows (login, checkout, create content)
- validation and error states
- edge cases (empty lists, slow network)
Avoid testing:
- implementation details
- trivial styles
3) Unit tests: best practices
- test pure functions (formatters, validators)
- deterministic inputs/outputs
- keep them fast
4) Integration tests: best practices
- test components with real interactions
- prefer “user sees X and can do Y”
Use tools like:
- React Testing Library
Interview note:
- RTL encourages testing behavior, not implementation.
5) E2E: best practices
- keep E2E suite small and focused
- test core flows
- stabilize selectors (data-testid)
Tools:
- Playwright / Cypress
6) Flaky tests: why they happen
- time-based waits
- real network dependencies
- shared state between tests
Fixes:
- mock network or use deterministic test server
- avoid arbitrary
setTimeout - reset state between tests
7) Interview Q&A
Q: What’s the best testing strategy?
- a balanced pyramid: many unit/integration tests + a few high-value e2e tests.
Q: What do you avoid testing?
- internal implementation details.
Summary checklist
- I can explain unit vs integration vs E2E.
- I can pick the right test type for a scenario.
- I avoid testing implementation details.
- I know how to reduce flakiness.
Summary
- Unit: fast and focused.
- Integration: behavior-based confidence.
- E2E: highest confidence for critical flows.
- Avoid flaky patterns and over-mocking.
Looking for structured, offline interview prep?
Free online lessons • Portable Amazon Kindle / Paperback
JavaScript Interview Guide
By Rajesh Dhiman
Deep dive into the Event Loop, microtask draining, closures, prototypal inheritance, and asynchronous execution patterns.
Frontend Interview Guide (2025 Edition)
By Rajesh Dhiman
Comprehensive preparation covering React internals, Web Performance, CSS architecture, and system design questions.
Note: All lessons on Frontend Interview remain completely free to read online. As an Amazon Associate, we may earn from qualifying purchases.
Written by Rajesh Dhiman
Authored by Rajesh Dhiman and engineered at Eunix Tech. Focused on deep-dive frontend engineering, JavaScript runtime internals, React architecture, and web performance.