Fakes vs (Stubs & Mocks) in Software Integration Testing

Use Fakes; Avoid Stubs or Mocks.

Zhimin Zhan

--

This article deviates from my usual topic: end-to-end test automation, on unit/integration testing, i.e. programmer’s domain. I am also a programmer, in fact, won an international programming award. After switching my day work from Programming to Automated Testing in 2010, I have solely developed and maintained (thanks to end-to-end via UI test suites) several highly acclaimed apps, in my spare time.

The idea of “Good software engineers write unit and integration tests” was well accepted over a decade ago. However, most programmers don’t know how to write good unit/integration tests. They spend a considerable amount of time (often much more than coding) on unit/integration testing, to avoid being labelled “not a good programmer”.

Most Automated Tests Suck” — James Shore, author of The Art of Agile Development.

“toMockOrNotToMock” post on Reddit

However, those poor-quality tests usually turn out to be a maintenance nightmare. One main technical aspect is using Mocks or Stubs wrongly. They should use Fakes instead. This article will share my experience on this (since 2007).

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.