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!