Skip to catalogue

218

test double

also mock, stub, fake

A stand-in for a collaborator. A fake has behavior. A mock only remembers it was called.

What is test double?

A test double replaces a dependency. A stub returns canned data. A fake is a simpler working version, such as an in-memory queue. A mock asserts the calls. If the double is the only thing the test exercises, you tested the double.

Why does test double matter when vibe coding?

Models mock the database, the clock, and the function under test. The suite is green and the query is wrong. Use a fake with real behavior, or a database in a transaction you roll back.

How do you do test double?

Fake or call the real dependency when it has logic. Mock only an edge you do not own, such as a payment HTTP API. Do not mock the unit you are testing. Assert the result a caller would see.

How do you ask a model for test double?

Test (behavior) with a fake (dependency), not a mock of the database. Do not mock the function under test. Assert the result a caller sees. A mock is only for an external API you cannot run.

What goes wrong with test double?

`toHaveBeenCalledWith` as the only assertion. An empty function that calls the mock and returns nothing still passes.

adjacent