This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

get

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

Construct object to define mock property get behavior

Syntax

getBehavior = get(behavior)

Description

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

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 PropertyGetBehavior and set up the behavior. The mock returns "David" when you get the value of the Name property.

getBehavior = get(behavior.Name);
testCase.assignOutputsWhen(getBehavior,"David")

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

testCase.assignOutputsWhen(get(behavior.Name),"David")

Access the Name property.

name = mock.Name
name = 
"David"

Introduced in R2017a