Pcornel
Automation · Testing

Mocks

Cheat sheet · https://pcornel.dk/topic.php?topic=5933

Back to the Topic

Answer

Mocks replace external dependencies with controlled test doubles so a unit or narrow component can exercise specified interactions, errors and edge cases deterministically.

Remember

  • Mock contract ≠ real dependency behavior.
  • Mock call expectation met ≠ downstream side effect occurred.
  • Detailed mock interactions ≠ user-visible behavior correct.
  • Simulated failure ≠ real timeout/retry semantics reproduced exactly.

First checks

  • python3 -c 'from unittest import mock' — mocking library
  • Mock in Pester — PowerShell
  • Recorded API responses (vcr/responses) — replay

Verify in this order

test → mock dependency → assertions

Where it usually breaks

Mocks prove local behavior against the simulated contract only; they cannot prove real protocol quirks, timing, authorization or side effects.

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Mocks testing proof-boundary map

BoundaryHealthy evidenceSuspicious evidence
Scope / oracleRequirement, case, expected result and exercised scope are explicitA generic green status exists without a trustworthy oracle or coverage boundary
Fixture / environmentData, dependencies and environment versions are reproducibleShared state, floating versions or stale fixtures make results non-reproducible
Effective outcomeAuthoritative state/read-back and service-relevant evidence match the expected resultTool/test/validator success substitutes for effective target or workload proof
Limits / next actionCoverage limits, unknowns and failures drive the next narrower checkUnknown evidence becomes pass, retries hide failures or broad success is inferred from one check

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5933

Confirmation

Confirm action

Continue?