谷歌测试错误:未知文件:“模拟函数没有默认操作集,其返回类型没有默认值集。”

问题描述 投票:0回答:0

我知道它报告的错误是因为模拟没有默认操作。 但是,在我的代码中已经有对 EXPECT_CALL 的操作。 我的其他测试用例对于类似的 EXPECT_CALL 和它的动作都很好。 无法找到此报告错误的原因

测试代码

#include Derived.hpp

TEST_F(ContainerTest, Test1) {
    EXPECT_CALL(m_Base, enProcessMessage(_)).WillRepeatedly(Return(CONSUME_MESSAGE));
    Message poMsg(MsgID_Draw);
    m_Derived->enProcessMessage(&poMsg);
}

待测模块

 MessageStatus Container::enProcessMessage(Message *const poMyMsg)
{
    MessageStatus enRetMsgTyp = PASS_MESSAGE;

    if (poMyMsg != NULL)
    {
        /* call base class */
        enRetMsgTyp = Base::enProcessMessage(poMyMsg);
        switch (poMyMsg->u16GetID())
        {
            //do something//
        }
    }
}

模拟.hpp

#include Base.hpp

struct MockBase
{
    MockBase();
    ~MockBase();
    MOCK_METHOD1(enProcessMessage2, enMessageStatus(Message*));
    //other mocks
};


模拟.cpp

#include MockBase.hpp

MessageStatus Base::enProcessMessage(Message * const poMessage_)
{
    return poMockBase ? poMockBase->enProcessMessage(poMessage_) : PASS_MESSAGE;         
}

尝试更改为不同的函数签名,因为整个项目具有相同的函数签名但在不同的类中,以防找不到正确的模拟函数。 甚至努力注释掉其他功能并通过消除过程,这是由于基类模拟功能。

c++ unit-testing googletest googlemock
© www.soinside.com 2019 - 2024. All rights reserved.