Main Content


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

Construct object to define mock property get behavior


getBehavior = get(behavior)


getBehavior = get(behavior) constructs a PropertyGetBehavior object to define mock property get behavior. Typically you use the get method to construct the PropertyGetBehavior 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 PropertyGetBehavior and set up the behavior. The mock returns "David" when you get the value of the Name property.

getBehavior = get(behavior.Name);

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


Access the Name property.

name = mock.Name
name = 

Version History

Introduced in R2017a