repeat
类: matlab.mock.actions.AssignOutputs
包: matlab.mock.actions
重复定义返回值
语法
repeat(action,n)
输入参数
示例
提示
如果您重复执行某一动作,并且随后不调用
then
方法,则该 mock 会继续返回重复的值。例如,请考虑某个银行帐户类的以下 mock。import matlab.mock.actions.AssignOutputs testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedProperties',"IsJointAccount");
如果您重复执行某项动作以返回属性值
true
两次,以下代码将会继续运行,以便第三次和第四次获取该属性值,因此总共四次返回true
。when(get(behavior.IsJointAccount),AssignOutputs(true).repeat(2)) for i = 1:4 tf = mock.IsJointAccount end
但以下代码返回
true
和false
各两次。when(get(behavior.IsJointAccount), ... AssignOutputs(true).repeat(2).then(AssignOutputs(false))) for i = 1:4 tf = mock.IsJointAccount end
版本历史记录
在 R2017a 中推出