Main Content

withExactInputs

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

Specify mock object method call with only object as input

Syntax

callBehavior = withExactInputs(behavior)

Description

callBehavior = withExactInputs(behavior) returns a MethodCallBehavior object to define behavior when mock object method is called with only the object as an input.

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 behavior. If the method is called with only the object as input, return "hello".

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

Call the method with only the object as an input.

output = myMethod(mock)
output = 
"hello"

Call the method with additional inputs. Since this behavior is not defined, the mock returns the default value.

output = mock.myMethod(123)
output =

     []

Verify that the method was called at least once with only the object as an input.

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

Version History

Introduced in R2017a