Main Content


Class: matlab.mock.PropertyGetBehavior
Package: matlab.mock

Specify mock object property access action




when(behavior,action) specifies the action that a mock object property takes when it is accessed.

Input Arguments

expand all

Behavior of the mock, specified as a matlab.mock.PropertyGetBehavior instance. To create an instance of matlab.mock.PropertyGetBehavior, call the matlab.mock.PropertyBehavior.get method with the behavior object.

Example: get(myMockBehavior.MyProperty)

Defined action, specified as an instance of matlab.mock.actions.ReturnStoredValue or matlab.mock.actions.ThrowException.

Example: ReturnStoredValue

Example: ThrowException(MException('Account:deposit:Negative','Deposit amount must be positive.'))


expand all

Create a mock for a person class. The mock has one property, Name.

testCase = matlab.mock.TestCase.forInteractiveUse;
[mock,behavior] = testCase.createMock('AddedProperties',"Name");

Set up the behavior. When the property is accessed, return the value "David".

import matlab.mock.actions.AssignOutputs

Access the property.

name = mock.Name
name = 
Introduced in R2017a