Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.mock.actions.StoreValue class

Package: matlab.mock.actions

Store property value

Description

The StoreValue action specifies that the specified value is stored when setting a property.

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

Construction

action = StoreValue stores a property value.

Methods

repeatRepeat same action multiple times
thenSpecify action

Copy Semantics

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

Examples

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 set access to PropA.

import matlab.mock.actions.StoreValue;
when(set(behavior.PropA),StoreValue);

Use the mock.

mock.PropA = 1;

Use the mock.

mock.PropB = 2;
Interactive assertion failed.

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

Alternatives

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

Introduced in R2017a

Was this topic helpful?