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

Package: matlab.mock

Match any number of arguments

Description

Use the AnyArguments class to match any number of arguments when specifying mock behavior or qualifying mock interactions.

Construction

AnyArguments matches an unlimited, unspecified number of arguments, including zero. When defining mock behavior or qualifying mock interactions, specify AnyArguments as the last argument in the argument list.

Copy Semantics

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

Examples

expand all

Match any number of arguments.

import matlab.mock.AnyArguments
import matlab.mock.actions.ThrowException

testCase = matlab.mock.TestCase.forInteractiveUse;

% Create a mock for a bank account class
[saboteurAccount,behavior] = testCase.createMock('AddedMethods',"deposit");

% Define behavior to throw exception with any input argument
when(behavior.deposit(AnyArguments),ThrowException)

% All of the following interactions throw an exception:
saboteurAccount.deposit;
saboteurAccount.deposit(-10);
saboteurAccount.deposit(10);
saboteurAccount.deposit('a','b','c');

Alternatives

The AnyArguments class is functionally similar to using the withAnyInputs method of the matlab.mock.MethodCallBehavior class. For example, the following code blocks are similar.

% Using the AnyArguments class
import matlab.mock.AnyArguments;
testCase.verifyCalled(behavior.myMethod(AnyArguments));

% Using the withAnyInputs method
testCase.verifyCalled(withAnyInputs(behavior.myMethod))
However, AnyArguments requires that the mock is the first input argument, and withAnyInputs does not. The MethodCallBehavior class provides additional methods to specify behavior and record interactions, such as specification of exact inputs or a number of outputs.

Introduced in R2017a

Was this topic helpful?