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
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.Speed
Replacing slow objects with fast simulations.Scenarios
Mock objects may simulate scenarios and data that are difficult to produce with real objects.Predictability
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 | ||
Type | CodingUnit Testing | |
Definition | Objects that implement the same interface as real objects but simulate their implementation. | |
Value | TestingReplacing unavailable, troublesome, unpredictable or slow objects in particular environments. | |
Related Concepts |