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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

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.


expand 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

Was this topic helpful?