Test Double: Stub (Meszaros)
Details
Core Concepts:
- Purpose
-
Provides predefined (canned) responses to calls made during a test. Does not verify interactions — only supplies data.
- Behavior
-
Returns fixed values regardless of input. No assertion on whether or how it was called.
- Distinction from Mock
-
A Stub never fails a test. It only provides data. A Mock has expectations and can fail the test if interactions are wrong.
- Key Proponent
-
Gerard Meszaros ("xUnit Test Patterns", 2007)
When to Use:
-
Tell an LLM: "Create a Stub test double that returns this fixed data"
-
Isolating the system under test from external dependencies (database, API)
-
State-based testing (Chicago School TDD)
-
When you care about the result, not about how it was obtained
Related Anchors:
-
Test Double (Meszaros) — umbrella taxonomy
-
Spy — a Stub that also records calls
-
Mock — when you need interaction verification
-
TDD, Chicago School — favors Stubs over Mocks