matlab.mock.actions.AssignOutputs - Define return values for method called or property accessed - MATLAB (original) (raw)

Namespace: matlab.mock.actions

Define return values for method called or property accessed

Description

To specify the values that the framework returns when a mock object method is invoked or a mock object property is accessed, use the AssignOutputs class.

If you call a mocked method with fewer outputs than specified by AssignOutputs, the remaining outputs are discarded. If you call a mocked method with more outputs than specified by AssignOutputs, MATLABĀ® throws an error.

Construction

action = AssignOutputs([A1,...,An](#bvisu9e-1-A1An)) defines the values for the mock object to return for a method call or property access. The AssignOutputs constructor accepts one or more values, A1,...,An, that correspond to the values for the output arguments of the mock object method or the value of the mock object property.

Input Arguments

expand all

Return values, specified as scalars, vectors, matrices, or multidimensional arrays. Return values can be any data type.

Example: "mySpecifiedValue"

Example: 7,13,42

Example: [1 2 3;4 5 6]

Properties

expand all

Predefined return values, returned as a cell array of arguments. Return values are specified during class construction, and can be any data type.

Data Types: cell

Methods

repeat Repeat defining return values
then Action for mock object interaction or action subsequent to defining return values

Copy Semantics

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

Examples

collapse all

Create a mock for a quadrilateral class.

testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedMethods',"sideLengths");

Set up behavior.

import matlab.mock.actions.AssignOutputs; when(withAnyInputs(behavior.sideLengths),AssignOutputs(2,2,4,4))

Use the mock.

[a,b,c,d] = mock.sideLengths

Tips

Alternatives

For simple definition of outputs, you can use the assignOutputsWhen method of the matlab.mock.TestCase class. However, there is more functionality when you use the AssignOutputs action.

Version History

Introduced in R2017a