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.
|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|
|Constraint qualifying mock object interactions|
|Constraint determining property get access|
|Constraint determining method call|
|Constraint determining property set interaction|
|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|
Test a portion of a complete system in isolation using a mock.
Define behavior for mocked methods and properties. For example, you can specify that a method returns predefined values.
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.
This example shows how to write a test that uses the app testing framework and the mocking framework.