Class: matlab.mock.TestCase
Package: matlab.mock

Return stored value when property is accessed




returnStoredValueWhen(testcase,behavior) specifies that the mock returns the stored property value when a property is accessed. If the mock is strict and the property is an abstract property of the mock interface, the framework produces an assertion failure when it accesses a property. To enable access to the property in a strict mock, use the returnStoredValueWhen method.

Input Arguments

expand all

Instance of the test case, specified as a matlab.mock.TestCase object.

Behavior of the mock, specified as a matlab.mock.PropertyGetBehavior instance. To create an instance of matlab.mock.PropertyGetBehavior, call the get method on a property of the behavior object.

Example: get(behavior.MyMockedProperty)


expand all

Create a strict mock. All property interactions throw exceptions by default.

testCase = matlab.mock.TestCase.forInteractiveUse;
[mock,behavior] = testCase.createMock('AddedProperties',"PropertyFoo",...

Enable PropertyFoo to be accessed instead of throwing an exception.



Using the returnStoredValueWhen method is functionally equivalent to using the matlab.mock.actions.ReturnStoredValue action with the when method of the PropertyGetBehavior class. For example, the following code blocks are functionally equivalent.

% Using the returnStoredValueWhen method

% Using the ReturnStoredValue action with the when function
import matlab.mock.actions.ReturnStoredValue;
However, there is more functionality when you use the ReturnStoredValue action. For instance, you can specify different subsequent behavior for the same mocked object interaction.

Introduced in R2017a