Skip to content

Origin

The term comes from espionage: a spy observes without acting, records without judging. The software sense was formalised by Meszaros in 2007.

Espionage uses "spy" for an operative who watches and reports. The software sense borrowed the metaphor in the mid-2000s as mocking frameworks matured and developers needed a double that observed rather than asserted. Meszaros' xUnit Test Patterns (2007) formalised it as one of five doubles; Fowler's Mocks Aren't Stubs (2007) placed it in the taxonomy; Sinon.js (2011) made it a first-class primitive in JavaScript testing, and Jest (2014) followed.

  1. 2007 — Meszaros formalises Test Spy in xUnit Test Patterns

  2. 2007 — Fowler's Mocks Aren't Stubs positions spies in the taxonomy

  3. 2011 — Sinon.js ships spies, stubs and mocks as distinct primitives

  4. 2014 — Jest introduces jest.fn() with spy semantics

  5. 2020 — Mockito and pytest consolidate spy patterns in Java/Python

  6. 2024 — Mozilla testing guidelines recommend spies over strict mocks

A Test Spy is a double that captures the indirect output of the system under test so that the test can verify the indirect output.

— Gerard Meszaros, *xUnit Test Patterns*, 2007
2007 · Meszaros formaliza Test Spy
2011 · Sinon.js con spies, stubs y mocks como primitivas
2014 · Jest jest.fn() con semántica de spy
5 · dobles de pruebadummy, stub, spy, mock, fake
1 · assertion mínima por spy para no ser dead weight