Main Content

repeat

Class: matlab.mock.actions.DoNothing
Namespace: matlab.mock.actions

Repeat taking no action

Since R2020a

Description

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.

example

Input Arguments

expand all

Defined action, specified as a matlab.mock.actions.DoNothing object.

Example: action = DoNothing

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

Example: 5

Examples

expand all

Create a mock for a bank account class.

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

Specify behavior. Use repeat for two repetitions of no action, and then allow the Deposit property to be set in the third attempt.

import matlab.mock.actions.DoNothing
import matlab.mock.actions.StoreValue
when(set(behavior.Deposit), ...
    DoNothing().repeat(2).then(StoreValue))

Use the mock.

for i = 1:3
    mock.Deposit = 100
end
mock = 
  Mock with properties:

    Deposit: []

mock = 
  Mock with properties:

    Deposit: []

mock = 
  Mock with properties:

    Deposit: 100

Version History

Introduced in R2020a