matlab.mock.actions.ReturnStoredValue class

Package: matlab.mock.actions

Return stored property value


The ReturnStoredValue action specifies that the stored value is returned when accessing a property.

By default, when you access property values in strict mocks, MATLAB® throws an exception. To specify that the framework returns the stored value of a mock object property, use the ReturnStoredValue class.


action = ReturnStoredValue returns the stored property value.


repeatRepeat same action multiple times
thenSpecify action

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.


collapse all

Create a strict mock. By default, property interactions throw exceptions.

testCase = matlab.mock.TestCase.forInteractiveUse;
properties = ["PropA" "PropB" "PropC"];
[mock,behavior] = testCase.createMock('AddedProperties',properties,"Strict",true);

Enable access to PropA.

import matlab.mock.actions.ReturnStoredValue;

Use the mock.

val1 = mock.PropA
val1 =

val2 = mock.PropB
Interactive assertion failed.

Test Diagnostic:
Unexpected access of strict mock property 'PropB'.
Assertion failed.


For a simple directive to return property values, you can use the returnStoredValueWhen method of the matlab.mock.TestCase class. However, there is more functionality when you use the ReturnStoredValue action.

Introduced in R2017a