Class: matlab.mock.actions.AssignOutputs
Package: matlab.mock.actions
Repeat defining return values
repeat(n,action)
If you repeat an action, and do not follow it with
a call to the then
method, the mock continues to
return the repeated value. For example, consider the following mock
of a bank account class.
import matlab.mock.actions.AssignOutputs testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedProperties',"IsJointAccount");
If you repeat an action to return a property value of true
twice,
the following code, which goes on to get the property value a third
and fourth time, returns true
all four times.
when(get(behavior.IsJointAccount),then(repeat(2,AssignOutputs(true)))); for i = 1:4 tf = mock.IsJointAccount end
But the following code returns true
twice
and false
twice.
when(get(behavior.IsJointAccount),then(repeat(2,AssignOutputs(true)), ... then(AssignOutputs(false)))); for i = 1:4 tf = mock.IsJointAccount end