Test Workflows with Mocks

Unit tests can be useful for specifying parameters, results, how algorithms should behave, and many other things, but they can’t test that a sequence of calls are in the right order, or other similar scenarios. For that you need another kind of testing called workflow testing.

Workflow testing uses something called mocks. Mocks are stand-ins for real objects. They’re only used in the context of the test, and they verify how the code you’re testing interacts with an external dependency. Anything external that’s needed in the code you’re testing has to be mocked out, and a variety of techniques and tools are available to do that.

Condition the mock to say that when it’s called with a certain set of values it should return ...