I'm using googlemock 1.6.0 to set expectations on my class's destructor using
the Die() pattern described in the cookbook. I've been using NiceMock to hide "uninteresting mock" warnings, but Die() brings them back.
The tests below demonstrate how
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::NiceMock;
struct MyObject {
virtual ~MyObject() {}
virtual void MyFunction() = 0;
};
struct MyObjectMock : public MyObject {
virtual ~MyObjectMock() {}
MOCK_METHOD0(MyFunction, void ());
};
struct MyDieObjectMock : public MyObject {
virtual ~MyDieObjectMock() { Die(); }
MOCK_METHOD0(Die, void ());
MOCK_METHOD0(MyFunction, void ());
};
struct MyObjectTest : public ::testing::Test {};
TEST_F(MyObjectTest, NickMockPreventsUninterestingWarning) {
// Uninteresting function warnings are suppressed here, as expected
NiceMock<MyObjectMock> lMyObject;
lMyObject.MyFunction();
}
TEST_F(MyObjectTest, CallToDieTriggersUninterestingWarning) {
// Uninteresting function warning about Die gets raised here, but shouldn't
NiceMock<MyDieObjectMock> lMyObject;
lMyObject.MyFunction();
}
And just for completeness, the output I get is:
[----------] 2 tests from MyObjectTest
[ RUN ] MyObjectTest.NickMockPreventsUninterestingWarning
[ OK ] MyObjectTest.NickMockPreventsUninterestingWarning (0 ms)
[ RUN ] MyObjectTest.CallToDieTriggersUninterestingWarning
GMOCK WARNING:
Uninteresting mock function call - returning directly.
Function call: Die()
Stack trace:
[ OK ] MyObjectTest.CallToDieTriggersUninterestingWarning (4 ms)
[----------] 2 tests from MyObjectTest (5 ms total)
I had expected the "uninteresting mock function" warning about Die() to be suppressed.
Thanks!