Main Content

matlab.mock.actions.ReturnStoredValue class

Package:matlab.mock.actions

Return stored property value

Description

TheReturnStoredValueaction 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 theReturnStoredValueclass.

Construction

action = ReturnStoredValue返回存储属性值。

Methods

repeat Repeat returning stored property value
then Action for mock object interaction or action subsequent to returning stored 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 access toPropA.

importmatlab.mock.actions.ReturnStoredValuewhen(get(behavior.PropA),ReturnStoredValue)

Use the mock.

val1 = mock.PropA
val1 = []
val2 = mock.PropB
Assertion failed. ---------------- Test Diagnostic: ---------------- Unexpected access of strict mock property 'PropB'.Assertion failed.

Alternatives

For a simple directive to return property values, you can use thereturnStoredValueWhenmethod of thematlab.mock.TestCaseclass. However, there is more functionality when you use theReturnStoredValueaction.

Version History

Introduced in R2017a