The SDET Playbook

← All questions

When should I mock or stub dependencies, and when does mocking hide real bugs?

Asked Sep 28, 2026Viewed 0 times

1 Answer

Sign in to answer and to vote.

  • 0
    The SDET PlaybookSep 28, 2026

    Mock what is slow, non-deterministic or outside your control, and prefer real objects or fakes elsewhere. Google's gMock guidance says generally not to mock classes you don't own, and Google's testing posts recommend using the real implementation first, then a maintained fake, and only then a wrapper you control. Overuse is a design smell: mocks that return other mocks, or tests that assert call sequences, break on every refactor and can pass while the real integration is broken. Mocks hide bugs when they encode your assumptions about a service; contract tests or a test against a real container close that gap.

    Sources: gMock guide, Google Testing Blog, Fowler