repeat

Class: matlab.mock.actions.DoNothing
Package: matlab.mock.actions

Repeat taking no action

Description

example

repeat(n,action) repeats the same action n times.

Input Arguments

expand all

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

Example: 5

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

Example: DoNothing

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),then(repeat(2,DoNothing),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

Introduced in R2020a