set
类: matlab.mock.PropertyBehavior
包: matlab.mock
构造对象以定义 mock 属性的 set 行为
语法
setBehavior = set(behavior)
说明
setBehavior = set(
构造 behavior
)PropertySetBehavior
对象来定义 mock 属性的 set 行为。通常情况下,当您定义 mock 行为时,可使用 set
方法来隐式构造 PropertySetBehavior
。
输入参数
behavior
— mock 的行为
matlab.mock.PropertyBehavior
实例
mock 的行为,指定为 matlab.mock.PropertyBehavior
实例。要创建 matlab.mock.PropertyBehavior
实例,请访问行为对象的属性。
示例: myMockBehavior.MyProperty
示例
使用 PropertySetBehavior
对象定义行为
使用 Name
属性为 person 类创建一个 mock。
testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedProperties',"Name");
创建一个 PropertySetBehavior
对象并设置其行为。当您设置 Name
属性的值时,mock 将引发异常。
setBehavior = set(behavior.Name); testCase.throwExceptionWhen(setBehavior)
您也可以使用行为定义隐式创建 PropertySetBehavior
对象。
testCase.throwExceptionWhen(set(behavior.Name))
设置 Name
属性的值。
mock.Name = "Andy";
Error using matlab.mock.internal.MockContext/createMockObject/mockPropertySetCallback (line 420) The following property set was specified to throw an exception: <Mock>.Name = "Andy"
版本历史记录
在 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)