when
Class: matlab.mock.PropertyGetBehavior
Namespace: matlab.mock
Specify mock object property access action
Syntax
when(behavior,action)
Description
when(
specifies
the action that a mock object property takes when it is accessed.behavior
,action
)
Input Arguments
behavior
— Behavior of mock
matlab.mock.PropertyGetBehavior
instance
Behavior of the mock, specified as a matlab.mock.PropertyGetBehavior
instance.
To create an instance of matlab.mock.PropertyGetBehavior
,
call the matlab.mock.PropertyBehavior.get
method
with the behavior object.
Example: get(myMockBehavior.MyProperty)
action
— Defined action
instance of matlab.mock.actions.ReturnStoredValue
| instance of matlab.mock.actions.ThrowException
Defined action, specified as an instance of matlab.mock.actions.ReturnStoredValue
or matlab.mock.actions.ThrowException
.
Example: ReturnStoredValue
Example: ThrowException(MException('Account:deposit:Negative','Deposit
amount must be positive.'))
Examples
Specify Mock Property Access Behavior
Create a mock for a person class. The mock has one property, Name
.
testCase = matlab.mock.TestCase.forInteractiveUse; [mock,behavior] = testCase.createMock('AddedProperties',"Name");
Set up the behavior. When the property is accessed, return the value "David"
.
import matlab.mock.actions.AssignOutputs when(get(behavior.Name),AssignOutputs("David"))
Access the property.
name = mock.Name
name = "David"
Version History
Introduced in R2017a
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)