MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Assign the value of 1138 and then 237 to the ID property. Then, throw an exception for
property access. Each call to the then method accepts up to two actions. To specify more
subsequent actions, use multiple calls to then.


when(get(behaviorObj.ID),then(AssignOutputs(1138), ...
then(AssignOutputs(237),ThrowException)))
id = mock.ID
id = mock.ID
id = mock.ID


id =


1138


id =


237


Error using matlab.mock.internal.MockContext/createMockObject/mockPropertyGetCallback (line 346)
The following property access was specified to throw an exception:


.ID

If the object is the only input value, specify the findUser function return the value of
"Phil" twice.


when(withExactInputs(behaviorObj.findUser),repeat(2,AssignOutputs("Phil")))
n = mock.findUser
n = mock.findUser


n =


"Phil"


n =


"Phil"


Call the function a third time. If you repeat an action, and do not follow it with a call to
the then method, the mock continues to return the repeated value.


n = mock.findUser


Specify Mock Object Behavior
Free download pdf