Hasty Briefsbeta

Bilingual

“Don’t mock what you don't own” in 5 minutes (2022)

a year ago
  • #mock-objects
  • #testing
  • #software-development
  • The 'Don’t Mock What You Don’t Own' principle advises against mocking third-party dependencies in tests.
  • Mocking third-party objects can lead to brittle and complex tests, making the test intent unclear.
  • Introducing a thin abstraction layer (façade) around third-party dependencies simplifies testing and improves business logic clarity.
  • The principle is a heuristic rather than a strict rule, with exceptions for simple APIs or simulating hard-to-reproduce errors.
  • Alternatives to mocking include using verified fakes, stubs, or in-process servers for testing external API interactions.