A-Z Popular Blog Coding Search »
Related Guides
Unit Testing

6 Examples of a Test Stub

 , updated on
A test stub is quickly developed code that is used as a placeholder so that other sections of code can be unit tested. Test stubs typically return a hardcoded response that is in a valid format but completely static. They are useful for unit testing when dependencies aren't developed yet, aren't available, are unreliable, slow or difficult to setup with required test data. The following are illustrative examples.

Data Access

A stub for a data access object that isn't developed yet. Returns hardcoded values.


A developer uses a stub to simulate integration with systems that she can't connect to on her local environment.

Test Data

A developer uses a test stub to simulate a wide variety of responses from systems. For example, a developer may simulate rare response codes for a banking transaction that are difficult to arrange in development environments.

User Interface

A developer initially populates a web page with a hello world message to test that a redirect is working.


A module does frequent transactions with an external system that is often down. A developer implements a test stub to replace the calls to the system to increase the reliability of unit tests.


A software function involves algorithms that are computationally complex. A developer implements a test stub to temporarily replace such algorithms to speed their unit testing.
Overview: Test Stub
Unit Testing
Quickly developed code that is used as a placeholder to facilitate unit testing.
Unit testing when dependencies aren't ready, are unstable, slow or difficult to setup with required data.
Related Concepts
Unit Testing
Test Automation
Test Fixture
Test Harness
Test Drivers
Mock Object


This is the complete list of articles we have written about testing.
Acceptance Criteria
Acceptance Testing
Beta Release
Compliance Testing
Conformance Testing
Defect Density
Document Testing
Dry Run
Operational Testing
Performance Testing
Regression Testing
Sanity Testing
Test Cases
More ...
If you enjoyed this page, please consider bookmarking Simplicable.


A list of coding considerations and techniques.

Emergence vs Big Design Up Front

The difference between emergence and big-design-up-front.

Deep Magic

An overview of deep magic, a technology term.

Principle Of Least Astonishment

An overview of the Principle Of Least Astonishment.

Pull vs Push

The difference between pull and push technology.

Binary vs Hexadecimal

A comparison of binary and hexadecimal.

End-User Computing

An overview of end-user computing.

Library vs API

The difference between a library and API explained.

Code Reuse

The common types of code reuse.

Code Freeze

The common types of code freeze.

Mock Objects

A definition of mock objects with examples.
The most popular articles on Simplicable in the past day.

New Articles

Recent posts or updates on Simplicable.
Site Map