unit test mocking framework: verify a method was called in a sequence
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
David Hruska
il 27 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Mock Dependencies in Tests in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!