repeat
类: matlab.mock.actions.StoreValue
命名空间: matlab.mock.actions
重复存储属性值
语法
repeat(action,n)
输入参数
action
— 定义的动作
matlab.mock.actions.StoreValue
的实例
定义的动作,指定为 matlab.mock.actions.StoreValue
的实例。
n
— 重复动作的次数
整数
重复动作的次数,指定为整数。
示例: 5
示例
重复存储属性值
为 bank account 类创建一个 mock。
testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedProperties',"IsOpen");
指定其行为。允许 IsOpen
属性设置两次,然后引发异常。
import matlab.mock.actions.StoreValue import matlab.mock.actions.ThrowException when(set(behavior.IsOpen),StoreValue().repeat(2).then(ThrowException( ... MException('Account:setValue:tooMany','Value set too many times.'))))
使用 mock。
for i = 1:3 mock.IsOpen = i end
mock =
Mock with properties:
IsOpen: 1
mock =
Mock with properties:
IsOpen: 2
Error using matlab.mock.internal.MockContext/createMockObject/mockPropertySetCallback (line 429)
Value set too many times.
版本历史记录
在 R2017a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)