get
类: matlab.mock.PropertyBehavior
包: matlab.mock
构造对象以定义 mock 属性的 get 行为
语法
getBehavior = get(behavior)
说明
getBehavior = get(
构造 behavior
)PropertyGetBehavior
对象来定义 mock 属性的 get 行为。通常情况下,当您定义 mock 行为时,可使用 get
方法来隐式构造 PropertyGetBehavior
。
输入参数
behavior
— mock 的行为
matlab.mock.PropertyBehavior
实例
mock 的行为,指定为 matlab.mock.PropertyBehavior
实例。要创建 matlab.mock.PropertyBehavior
实例,请访问行为对象的属性。
示例: myMockBehavior.MyProperty
示例
使用 PropertyGetBehavior
对象定义行为
使用 Name
属性为 person 类创建一个 mock。
testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedProperties',"Name");
创建一个 PropertyGetBehavior
对象并设置其行为。当您获取 Name
属性的值时,mock 返回 "David"
。
getBehavior = get(behavior.Name);
testCase.assignOutputsWhen(getBehavior,"David")
您也可以使用行为定义隐式创建 PropertyGetBehavior
对象。
testCase.assignOutputsWhen(get(behavior.Name),"David")
访问 Name
属性。
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)