我在使用Google Mock(v1.7.0)实现纯虚拟界面时遇到问题。
为了确定根本原因,我将纯虚拟接口Simple
和MockSimple
放在一起作为测试。我相信我在这里所做的与this Google Mock example一致。
然而,当我编译它时,我收到一个错误。为什么是这样?我做错了什么?
#include "gmock/gmock.h"
#include "gtest/gtest.h"
class Simple
{
public:
virtual ~Simple() {}
virtual int Initialize() = 0;
};
class MockSimple : public Simple
{
public:
MOCK_METHOD0(Initialize, int());
};
TEST(Hello, MockSimple)
{
MockSimple m;
EXPECT_CALL(m, Initialize);
m.Initialize();
}
g++ -I../gmock/include/ -I../gmock/gtest/include -c test.cpp -o test.o
test.cpp: In member function ‘virtual void Hello_MockSimple_Test::TestBody()’:
test.cpp:20:5: error: ‘m.MockSimple::gmock_Initialize’ does not have class type
答案 0 :(得分:6)
需要在EXPECT_CALL中调用的方法的参数列表(在本例中为空):)
EXPECT_CALL(m, Initialize());