Main Content

matlab.mock.actions.StoreValue class

Package:matlab.mock.actions

Store property value

Description

TheStoreValueaction 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 theStoreValueclass.

Construction

action = StoreValuestores a property value.

Methods

repeat Repeat storing property value
then Action for mock object interaction or action subsequent to storing property value

Copy Semantics

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

Examples

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,“严格的”,true);

Enable set access toPropA.

importmatlab.mock.actions.StoreValuewhen(set(behavior.PropA),StoreValue)

Use the mock.

mock.PropA = 1;

Use the mock.

mock.PropB = 2;
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 thestoreValueWhenmethod of thematlab.mock.TestCaseclass. However, there is more functionality when you use theStoreValueaction.

Introduced in R2017a