MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Qualify Mock Method Interaction


Since the mock records interactions sent to it, you can qualify that a mock method was
called. Roll one die.


val = mock.roll(1);


Verify that the roll method was called with 1 die.


testCase.verifyCalled(behaviorObj.roll(1))


Interactive verification passed.


Verify that the roll method was called with 3 dice. This test fails.


testCase.verifyCalled(behaviorObj.roll(3), ...
'roll method should have been called with input 3.')


Interactive verification failed.




Test Diagnostic:


roll method should have been called with input 3.




Framework Diagnostic:


verifyCalled failed.
--> Method 'roll' was not called with the specified signature.
--> Observed method call(s) with any signature:
out = roll([1×1 matlab.mock.classes.Mock], 1)


Specified method call:
MethodCallBehavior
[...] = roll(, 3)


Verify that the roll method was not called with 2 dice.


testCase.verifyNotCalled(behaviorObj.roll(2))


Interactive verification passed.


Qualify Mock Object Interaction
Free download pdf