stub

A stand-in for a dependency in a test that simply returns prepared answers, without checking how it was called.

In more detail

Use a stub when you only need data for a local rule, such as feeding a parser a malformed response. Unlike a mock, it does not verify how the code used it.

Examples

In this course: Use a stub when the test's claim is about the answer your code produces. Hand-written stubs keep you honest about what the real collaborator returns. A mock whose calls nobody checks is really a stub.
class StubGateway:
    def charge(self, pence, reference):
        return {"reference": reference}

Related terms

Taught in

References