unit test mocking framework: verify a method was called in a sequence
2 views (last 30 days)
Show older comments
I want to verify that a method was called twice with inputs to be verified
I want to make sure that
cls.myfunc('first')
cls.myfunc('second')
occurred.
Example:
%setup
testCase = matlab.mock.TestCase.forInteractiveUse;
[mockedCls, behavior] = testCase.createMock('AddedMethods', 'myfunc');
%run
mockedCls.myfunc('first')
mockedCls.myfunc('second')
%verify -> THIS DOES NOT WORK
testCase.verifyThat([
behavior.myfunc('first')
behavior.myfunc('second')], WasCalledInCorrectOrder)
The verification code above is just an example. How would you do such a verification?
0 Comments
Answers (1)
David Hruska
on 27 Dec 2019
I know this reply is coming very late, but in case it's still helpful, this is now possible in R2019b using the Occurred constraint:
import matlab.mock.constraints.Occurred;
%setup
testCase = matlab.mock.TestCase.forInteractiveUse;
[mockedCls, behavior] = testCase.createMock('AddedMethods', "myfunc");
%run
mockedCls.myfunc('first')
mockedCls.myfunc('second')
%verify - this passes:
testCase.verifyThat([
behavior.myfunc('first')
behavior.myfunc('second')], Occurred("RespectingOrder",true));
%verify - this fails:
testCase.verifyThat([
behavior.myfunc('second')
behavior.myfunc('first')], Occurred("RespectingOrder",true));
0 Comments
See Also
Categories
Find more on Mock Dependencies in Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!