%% Assign Series of Outputs to Mock
% Create a mock for a class that represents a 6-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. Return 0 the first time it runs. On subsequent runs, invoke the randi function to return a random integer between 1 and 6.

import matlab.mock.actions.AssignOutputs
import matlab.mock.actions.Invoke
when(withExactInputs(behavior.roll),...
    then(AssignOutputs(0),...
        then(Invoke(@(~)randi(6)))))

% Call the mocked roll method three times.

val = mock.roll
val = mock.roll
val = mock.roll