withAnyInputs

Class: matlab.mock.MethodCallBehavior
Package: matlab.mock

Specify mock object method call with any number of inputs with any value

Syntax

withAnyInputs(behavior)

Description

withAnyInputs(behavior) specifies a mock object method call with any number of inputs that can have any value.

Input Arguments

expand all

Behavior of the mock, specified as a matlab.mock.MethodCallBehavior instance. To create an instance of matlab.mock.MethodCallBehavior, call a method of the behavior object.

Example: myMockBehavior.myMockedMethod

Examples

expand all

Create a mock with a myMethod method.

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

Set up the behavior. Regardless of the inputs to the method, it returns "hello".

testCase.assignOutputsWhen(withAnyInputs(behavior.myMethod),"hello")

Call the method with various inputs.

output = mock.myMethod
output = 
"hello"
output = mock.myMethod(123)
output = 
"hello"
output = myMethod("abc",mock)
output = 
"hello"

Verify that the method was called at least once with some set of inputs.

testCase.verifyCalled(withAnyInputs(behavior.myMethod))
Verification passed.

Introduced in R2017a