Main Content

withAnyInputs

Class: matlab.mock.MethodCallBehavior
Namespace: matlab.mock

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

Syntax

callBehavior = withAnyInputs(behavior)

Description

callBehavior = withAnyInputs(behavior) returns a MethodCallBehavior object to define behavior when mock object method is called 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.

Version History

Introduced in R2017a