Took me a while to figure out the culprit. Fast notes for future reference.
With omission to namespace, forward declaration, header inclusions, some irrelevant classes and logics for the purpose of this note.
Couple of notes:
- All methods from base class to be mocked must be virtual
- Destructor must be virtual, otherwise led to error (2)
- Object must be copiyable, thus if unique_ptr<> is used in the DUT class, general practice is to use a mock method to return a raw pointer
and transfer the ownership to the unique_ptr<> during test.
The errors:
1) Uninteresting mock
GMOCK WARNING:
Uninteresting mock function call - returning default value.
Function call: makeTheManagerMock()
Returns: NULL
2)
the_adaptor_test.cpp:68: ERROR: this mock object (used in test TestTheAdaptor.testCreateNode) should be deleted but never is. Its address is @0xc1a6d0.
ERROR: 1 leaked mock object found at program exit.
Reference:
http://wahz.blogspot.sg/2014/08/google-mock-dammit-gets-me-every-time.html
https://github.com/google/googletest/blob/master/googlemock/docs/FrequentlyAskedQuestions.md#i-get-a-heap-check-failure-when-using-a-mock-object-but-using-a-real-object-is-fine--what-can-be-wrong
No comments:
Post a Comment