Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse of the mock repository for a group of tests #104

Open
Brzesowsky opened this issue Mar 11, 2019 · 0 comments
Open

Reuse of the mock repository for a group of tests #104

Brzesowsky opened this issue Mar 11, 2019 · 0 comments

Comments

@Brzesowsky
Copy link

Brzesowsky commented Mar 11, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant