Main Content

set

Class: matlab.mock.PropertyBehavior
Namespace: matlab.mock

Construct object to define mock property set behavior

Syntax

setBehavior = set(behavior)

Description

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

Examples

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);
testCase.throwExceptionWhen(setBehavior)

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

testCase.throwExceptionWhen(set(behavior.Name))

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"

Version History

Introduced in R2017a