test spy

A test double that records how a function was called, with its arguments and results, so a test can check afterwards how it was used.

In more detail

A spy can wrap the real function and let it run while it watches, or answer with canned values like a stub. Tests then assert on things such as how many times it was called and with what arguments. Use one when the call itself is the behaviour you care about, such as one email sent or one charge requested.

Example

assert spy.calls == [(1000, "abc")]

Related terms

Taught in

References