Glossary · Automation software engineering and architecture
Test double
Also known as: Test stand-in
German: Test-Dummy
In software testing, a test double is any object or component that replaces a real dependency during a test, such as a dummy, stub, fake, spy or mock, so the code under test can be tested in isolation.
- Software engineering
In one sentence
A test double replaces a real dependency during a test, such as a stub, fake or mock, so the code under test runs in isolation.
Example
In the unit test of the recipe manager, a fake database in memory replaces the real SQL server.
How it applies
- Engineering: Test doubles remove slow, unavailable or nondeterministic dependencies such as hardware, networks and databases from unit tests. They are easiest to use when dependencies are injected through interfaces.
- Verification: Tests with doubles show that the unit works with the double. Integration tests with real components remain necessary.
- Documentation: Test specifications should state which dependencies were replaced and how, so reviewers can judge what a test demonstrates.
Kinds of test doubles
A dummy only fills parameters. A stub returns fixed answers. A fake has a simplified working implementation. A spy records calls. A Mock object verifies expected calls. The German list term Test-Dummy is used for the general concept here.