unit test mocking framework: verify a method was called in a sequence

3 visualizaciones (últimos 30 días)
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?

Respuestas (1)

David Hruska
David Hruska el 27 de Dic. de 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));

Categorías

Más información sobre Mock Dependencies in Tests en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by