concept

Test Doubles

Test doubles are objects or procedures used in software testing to replace real components that the system under test depends on, such as databases, web services, or complex classes. They simulate the behavior of these dependencies to isolate the unit being tested, ensuring tests run quickly, reliably, and without external interference. Common types include mocks, stubs, fakes, spies, and dummies, each serving different purposes in test scenarios.

Also known as: Test Fakes, Mock Objects, Stubs, Test Proxies, Test Stand-ins
🧊Why learn Test Doubles?

Developers should use test doubles when writing unit tests to isolate code from external dependencies, making tests faster and more deterministic by avoiding network calls, database access, or unpredictable behavior. They are essential in test-driven development (TDD) and continuous integration pipelines to ensure code quality without relying on real infrastructure, such as when testing a payment service without hitting actual payment gateways.

Compare Test Doubles

Learning Resources

Related Tools

Alternatives to Test Doubles