You might like this solution, which hides implementation details in the mock class.
In the mock class add:
using testing::_; using testing::Return; ACTION_P(IncrementAndReturnPointee, p) { return (*p)++; } class MockObject: public Object { public: MOCK_METHOD(...) ... void useAutoIncrement(int initial_ret_value) { ret_value = initial_ret_value - 1; ON_CALL(*this, aCertainFunction (_,_)) .WillByDefault(IncrementAndReturnPointee(&ret_value)); } private: ret_value; }
In the test, call:
TEST_F(TestSuite, TestScenario) { MockObject mocked_object; mocked_object.useAutoIncrement(0);
source share