oslac

Search

Search IconIcon to open search

Mocks

Published: Jun 1, 2023
Updated: Jun 3, 2023

Summary

Mock is a test double whose behavior is defined inline in a test. It has expectations about the way it should be called, and a test should fail if it is not called that way. Mocks are used to test interactions between objects, and are useful in cases where there are no other visible state changes or return results that you can verify1

Example

When your code reads from a disk and you want to ensure that it doesn’t do more than one disk read, you can use a mock to verify that the method that does the read is only called once.

Issues with Mocking


  1. Testing on the Toilet: Know Your Test Doubles ↩︎