Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Testing
Testingmedium

Mocks vs stubs vs fakes — what’s the difference?

Tags
#mocks#stubs#fakes
Back to categoryPractice quiz

Answer

Stubs provide fixed responses, mocks verify interactions, and fakes are lightweight implementations (e.g., in-memory DB). They serve different goals in tests.

Advanced answer

Deep dive

Pick the right substitute:

  • Stub: replace a dependency with canned outputs.
  • Mock: assert calls, arguments, or call order.
  • Fake: simplified but functional implementation.

Fakes are often more robust than mocks for integration-style tests.

Examples

Payment provider:

Stub: returns success
Mock: assert charge() called once with amount=100
Fake: in-memory ledger that records balances

Common pitfalls

  • Overusing mocks, making tests brittle.
  • Fakes that diverge from real behavior.
  • Stubs that hide important errors.

Interview follow-ups

  • When do you prefer a fake over a mock?
  • How do you keep fakes in sync with real services?
  • What is a spy and how is it different?