Skip to content

What it is

A stub is a test double that returns pre-programmed answers to calls, so a test can run without the real dependency.

A stub is the simplest useful test double. You give it a fixed response; it gives that response back whenever the code under test calls it. It does not verify that it was called, it does not record interactions, and it does not fail the test on its own. Its only job is to keep the test running.

Outside testing, "stub" means a placeholder. A Wikipedia stub is an article too short to be complete. A ticket stub is the half you keep after tearing. An API stub is an endpoint that returns a fixed shape before the real implementation exists.