Main Content


Class: matlab.mock.actions.Invoke
Namespace: matlab.mock.actions

Repeat invoking function handle




repeat(action,n) repeats the same action n times. You can specify the input arguments in any order. That is, repeat(action,n) and repeat(n,action) both repeat the action n times.

Input Arguments

expand all

Defined action, specified as an instance of matlab.mock.actions.Invoke.

Example: action = Invoke(@isempty)

Example: action = Invoke(@(~)randi(10))

Number of times to repeat the action, specified as an integer.

Example: 5


expand all

Create a mock for a class that represents a 12-sided die, including a mocked roll method.

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

Set up behavior for the roll method to return the value from the randi function twice and then return 0.

import matlab.mock.actions.AssignOutputs
import matlab.mock.actions.Invoke

when(withExactInputs(behavior.roll), ...

Call the mocked roll method four times.

val = mock.roll
val = 10
val = mock.roll
val = 11
val = mock.roll
val = 0
val = mock.roll
val = 0

Version History

Introduced in R2018b