Main Content

matlab.mock.AnyArguments class

Package:matlab.mock

Match any number of arguments

Description

Use theAnyArgumentsclass to match any number of arguments when specifying mock behavior or qualifying mock interactions.

Construction

AnyArgumentsmatches an unlimited, unspecified number of arguments, including zero. When defining mock behavior or qualifying mock interactions, specifyAnyArgumentsas the last argument in the argument list.

Copy Semantics

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

Examples

collapse all

Match any number of arguments.

importmatlab.mock.AnyArgumentsimportmatlab.mock.actions.ThrowExceptiontestCase = 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 argumentwhen(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

TheAnyArgumentsclass is functionally similar to using thewithAnyInputsmethod of thematlab.mock.MethodCallBehaviorclass. For example, the following code blocks are similar.

% Using the AnyArguments classimportmatlab.mock.AnyArguments; testCase.verifyCalled(behavior.myMethod(AnyArguments));% Using the withAnyInputs methodtestCase.verifyCalled(withAnyInputs(behavior.myMethod))
However,AnyArgumentsrequires that the mock is the first input argument, andwithAnyInputsdoes not. TheMethodCallBehaviorclass provides additional methods to specify behavior and record interactions, such as specification of exact inputs or a number of outputs.

Introduced in R2017a