Main Content

Mocking Framework

Isolate a portion of a system to test by imitating behavior of dependencies

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 usemock objectsto 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, seeCreate Mock Object.

Test a component using mocked-up dependencies.

Classes

expand all

matlab.mock.TestCase TestCaseto write tests with mocking framework
matlab.mock.AnyArguments Match any number of arguments
matlab.mock.actions.AssignOutputs Define return values for method called or property accessed
matlab.mock.actions.DoNothing Take no action
matlab.mock.actions.Invoke Invoke function handle when method is called
matlab.mock.actions.ReturnStoredValue Return stored property value
matlab.mock.actions.StoreValue Store property value
matlab.mock.actions.ThrowException Throw exception when method is called or when property is set or accessed
matlab.mock.constraints.Occurred Constraint qualifying mock object interactions
matlab.mock.constraints.WasAccessed Constraint determining property get access
matlab.mock.constraints.WasCalled Constraint determining method call
matlab.mock.constraints.WasSet Constraint determining property set interaction
matlab.mock.MethodCallBehavior Specify mock object method behavior and qualify method calls
matlab.mock.PropertyBehavior Specify mock object property behavior and qualify interactions
matlab.mock.PropertyGetBehavior Specify mock property get behavior
matlab.mock.PropertySetBehavior Specify mock object set behavior
getMockHistory Return history of mock interactions fromTestCaseinstance
matlab.mock.InteractionHistory.forMock Return history from mock object
matlab.mock.InteractionHistory Interface for mock object interaction history
matlab.mock.history Summary of classes representing mock object interaction history

Topics