When unit testing, you are often interested in testing a portion of a complete system isolated from dependencies. To test a portion of the system, we can use mock objects to replace the dependencies. A mock object implements at least part of the same interface as the production object, but often in a simpler, faster, more predictable, or more controllable way.
To get started, see Create Mock Object.
|Match any number of arguments|
Mock Object Actions
|Define return values for method called or property accessed|
|Take no action|
|Invoke function handle when method is called|
|Return stored property value|
|Store property value|
|Throw exception when method is called or when property is set or accessed|
Mock Object Constraints
|Constraint qualifying mock object interactions|
|Constraint determining property get access|
|Constraint determining method call|
|Constraint determining property set interaction|
Behavior Definition and Observation
|Specify mock object method behavior and qualify method calls|
|Specify mock object property behavior and qualify interactions|
|Specify mock property get behavior|
|Specify mock object set behavior|
Mock Object Interaction History
|Return history of mock interactions from |
|Return history from mock object|
|Interface for mock object interaction history|
|Summary of classes representing mock object interaction history|
- Create Mock Object
Test a portion of a complete system in isolation using a mock.
- Specify Mock Object Behavior
Define behavior for mocked methods and properties. For example, you can specify that a method returns predefined values.
- Qualify Mock Object Interaction
Intercept messages sent from the component under test to the mock object. For example, you can verify that a method was called or a property was set.
- Write Tests That Use App Testing and Mocking Frameworks
This example shows how to write tests that use the app testing framework and the mocking framework.