Test Doubles: Stubs, Mocks, and Fakes

Until now, we’ve just used the term external dependency double to refer to something that doubles as the external dependency. However, we can be more precise than that and define three kinds of doubles: stubs, mocks, and fakes. We already saw an example of a fake with SoggyWaffle.FakeWeatherAPI. A fake is just something that acts as the external dependency without calling out to the external dependency. A stub is a double where function implementations can be replaced on demand to do something in isolation, for example by replacing a function to do something in one test and something else in another. Stubs can be used to provide a different behavior of a given function based on the need of the test. Stubs ...

Get Testing Elixir 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.