unit test mocking framework: verify a method was called in a sequence
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
David Hruska
2019-12-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mock Dependencies in Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!