模拟:无趣的模拟函数调用vith对象返回

时间:2020-10-02 12:51:28

标签: c++ unit-testing

我正在编写程序来测试我的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()
}

0 个答案:

没有答案
相关问题