Checking your account

You can read the lesson while its saved answers and constructions load. Learning controls will open once that work is ready.

Dependency Injection and Test Doubles

unittest.mock and Controlled Dependencies

BOTIE

A test inherits the changing behavior of any real clock, database or remote service it uses. Testing terminology developed to distinguish stand-ins with different roles. Fowler's 2007 account separates checks on resulting state from expectations about how collaborators were called.

Python added unittest.mock to the standard library in version 3.3. It can record calls and supply controlled responses. An explicit callable parameter also makes that boundary visible without a mocking library. The resulting test still needs a clear account of what it establishes and which real integrations remain unchecked.

Sources for this history