我正在编写程序来测试我的c ++函数,但无法使用必须返回另一个对象的模拟函数。我不知道如何解决。
所以如果有人可以帮助我。
每次,我都会在测试结果中收到此消息:
GMOCK WARNING:
Uninteresting mock function call - returning default value.
Function call: getEventFree()
Returns: NULL
模拟功能:
class MockXF : iXF
{
public:
MOCK_METHOD(Event *, getEventFree, (), (override));
};
按钮功能:
class Button
{
public:
init(*iXF theXF){ixf = theXF}
start(){ixf->getEventFree(); //Use the event ...}
private:
iXF* ixf;
};
测试:
Event event;
MockXF mockxf;
// will create a segmentation fault which break the test
TEST_F(ButtonTest, Start)
{
Button button(&mockxf);
EXPECT_CALL(mockxf, getEventFree()).WillOnce(Return(&event));
button.start(); //This function called mockxf.getEventFree()
}