MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
n =

"Phil"

Define behavior for setting the value of Name. Throw an exception the first two times and
then store the value.

import matlab.mock.actions.StoreValue
when(set(behaviorObj.Name),then(repeat(2,ThrowException),StoreValue))
mock.Name = "John"

Error using matlab.mock.internal.MockContext/createMockObject/mockPropertySetCallback (line 368)
The following property set was specified to throw an exception:
<Mock>.Name = "John"

mock.Name = "Penny"

Error using matlab.mock.internal.MockContext/createMockObject/mockPropertySetCallback (line 368)
The following property set was specified to throw an exception:
<Mock>.Name = "Penny"

mock.Name = "Tommy"

mock =

Mock with properties:

Name: "Tommy"

Summary of Behaviors


Behavior TestCase Method matlab.mock.Actions
Class (Allows for
Definition of Repeat and
Subsequent Behavior)
Return specified values for
method call and property
access.

assignOutputsWhen AssignOutputs

Return stored value when
property is accessed.

returnStoredValueWhen ReturnStoredValue

33 Unit Testing

Free download pdf