Main Content


Class: matlab.mock.PropertyBehavior
Package: matlab.mock

Construct object to define mock property set behavior


setBehavior = set(behavior)


setBehavior = set(behavior) constructs a PropertySetBehavior object to define mock property set behavior. Typically you use the set method to construct the PropertySetBehavior implicitly when you define mock behavior.

Input Arguments

expand all

Behavior of the mock, specified as a matlab.mock.PropertyBehavior instance. To create an instance of matlab.mock.PropertyBehavior, access a property of the behavior object.

Example: myMockBehavior.MyProperty


expand all

Create a mock for a person class with a Name property.

testCase = matlab.mock.TestCase.forInteractiveUse;
[mock,behavior] = testCase.createMock('AddedProperties',"Name");

Create a PropertySetBehavior object and set up the behavior. The mock throws an exception when you set the value of the Name property.

setBehavior = set(behavior.Name);

Alternatively, you can create the PropertySetBehavior object implicitly with the behavior definition.


Set the value of the Name property.

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"
Introduced in R2017a