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.AssignOutputs class

Package: 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) 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

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 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

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.

Introduced in R2017a

Was this topic helpful?