Enter the Mock

Mocks, also sometimes referred to as test doubles,[13] are fake objects we periodically use in automated tests in place of real ones.

Now you may be wondering why on earth we’d ever want to do that. Isn’t it always better to test with the real thing? And the answer would normally be yes. Real objects don’t lie. They are easier to read. And there’s no magic in setting them up—they just work.

But there are occasions when calling the real thing may be problematic. One is when the service you are calling from your unit tests is expensive or slow.

images/mocking/mock-big.png

If you recall from Chapter 6, Covering Our Bases with Unit Tests, we always want our ...

Get The Way of the Web Tester now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.