when
类: matlab.mock.PropertyGetBehavior
包: matlab.mock
指定 mock 对象属性的访问操作
语法
when(behavior,action)
输入参数
behavior
— mock 的行为
matlab.mock.PropertyGetBehavior
实例
mock 的行为,指定为 matlab.mock.PropertyGetBehavior
实例。要创建 matlab.mock.PropertyGetBehavior
实例,请使用行为对象调用 matlab.mock.PropertyBehavior.get
方法。
示例: get(myMockBehavior.MyProperty)
action
— 定义的动作
matlab.mock.actions.ReturnStoredValue
的实例 | matlab.mock.actions.ThrowException
的实例
定义的操作,指定为 matlab.mock.actions.ReturnStoredValue
或 matlab.mock.actions.ThrowException
的实例。
示例: ReturnStoredValue
示例: ThrowException(MException('Account:deposit:Negative','Deposit amount must be positive.'))
示例
指定 mock 属性的 access 行为
为 person 类创建一个 mock。该 mock 有一个属性,即 Name
。
testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedProperties',"Name");
设置其行为。当访问该属性时,返回值 "David"
。
import matlab.mock.actions.AssignOutputs when(get(behavior.Name),AssignOutputs("David"))
访问属性。
name = mock.Name
name = "David"
版本历史记录
在 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)