This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


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