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

7 Examples of Mock Objects

 , updated on
Mock objects are components that implement the same interface as real components but simulate their implementation. The following are illustrative examples.

Unavailable Objects

Developers commonly test their code as they write it. In the context of a project or sprint, there are often dependencies that aren't available yet. Mock objects may be developed as disposable placeholders.


Integration to systems and services may be replaced with mock objects to speed development. This may be done because such integrations are unavailable or unreliable in certain environments.


Replacing slow objects with fast simulations.


Mock objects may simulate scenarios and data that are difficult to produce with real objects.


Replacing non-deterministic objects with a specific or predictable result set. For example, a mock object may replace a random number generator with a specific set of numbers.

Testing Inputs

One of the primary differences between a mock object and a test stub is that mock objects tend to have expectations. For example, they may validate inputs. This can be useful for testing scenarios such as integration where you want to make sure you're sending valid requests.

Destructive Testing

Replacing real objects with objects that behave badly to test non-functional requirements such as reliability and resilience.
Overview: Mock Objects
Unit Testing
Objects that implement the same interface as real objects but simulate their implementation.
Replacing unavailable, troublesome, unpredictable or slow objects in particular environments.
Related Concepts


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.
The most popular articles on Simplicable in the past day.

New Articles

Recent posts or updates on Simplicable.
Site Map