There seems to be no real documentation of the reset() function except an Assembla Wiki release comment:
"… If you have one mock repository for a group of tests, you can use the VerifyAll() function and the reset() function to reuse it for another time. ..."
The following is observed in Windows 7 with Visual Studio 2017, but should show the same behavior on any platform.
It works without reuse (snippet from test_cfuncs.cpp):
{
EQUALS(ret_1(), 1);
MockRepository mocks;
mocks.ExpectCallFunc(ret_1).Return(5);
EQUALS(ret_1(), 5);
}
EQUALS(ret_1(), 1);
Should is also work with reuse?
{
EQUALS(ret_1(), 1);
MockRepository mocks;
mocks.ExpectCallFunc(ret_1).Return(5);
EQUALS(ret_1(), 5);
mocks.VerifyAll();
mocks.reset();
EQUALS(ret_1(), 1); // <<== Exception raised
}
What is happening:
- DoExpectation() is called
- no optionals found
- raises ExpectationException(... funcName(NULL, 0))
- ExpectationException() constructor throws exception
- functionName = NULL
- for sure also repository.mocks.size == 0
To make the above reuse test case working the repository reset() function would need to delete all Replace objects within staticReplaces and call the clear() function of staticReplaces.
This is what the destructor of the MockRepository does.
There seems to be no real documentation of the reset() function except an Assembla Wiki release comment:
"… If you have one mock repository for a group of tests, you can use the VerifyAll() function and the reset() function to reuse it for another time. ..."
The following is observed in Windows 7 with Visual Studio 2017, but should show the same behavior on any platform.
It works without reuse (snippet from test_cfuncs.cpp):
{ EQUALS(ret_1(), 1); MockRepository mocks; mocks.ExpectCallFunc(ret_1).Return(5); EQUALS(ret_1(), 5); } EQUALS(ret_1(), 1);Should is also work with reuse?
{ EQUALS(ret_1(), 1); MockRepository mocks; mocks.ExpectCallFunc(ret_1).Return(5); EQUALS(ret_1(), 5); mocks.VerifyAll(); mocks.reset(); EQUALS(ret_1(), 1); // <<== Exception raised }What is happening:
To make the above reuse test case working the repository reset() function would need to delete all Replace objects within staticReplaces and call the clear() function of staticReplaces.
This is what the destructor of the MockRepository does.