I am writting unit tests with gmock. I have some uninteresting function calls in my test body for which I would like to suppress the gmock warnings. However, I have tried several ways like NiceMock or EXPECT_CALL, but none of them are working. Here are something I have tried:
class MockClass : public OriginClass {
// class body
int aFunc();
}
NiceMock<std::vector<MockClass> > mock_vector;
NiceMock<MockClass> tmp;
mock_vector.push_back(tmp);
EXPECT_CALL(tmp, aFunc())
.WillRepeatedly(Return(1));
But I keep get gmock warning of uninteresting function call. Can anyone help?
OK, so finally I found the answer myself.
The problem is that gmock doesn't provide a move constructor for NiceMock. so we have to change the vector of class to a vector of unique_ptr, and the problem is solved.
concretely, it should be like this:
std::vector<std::unique_ptr<NiceMock<MockClass>>> my_mockclass;
when pushing new elements back, you should use:
my_mockclass.emplace_back(std::make_unique<NiceMock<MockClass>>());
It should solve the problem. :)