Google模拟测试C ++当模拟是私有成员时如何设置EXPECT_CALL

时间:2019-01-30 16:29:46

标签: googletest

我有一个类在要测试的类中被模拟为私有

// in consumergroup.h
template<class Consumer>
class ConsumerGroup
{
public:
    int start(); // starts all internal consumers
    int stop(); // stops all internal consumers

private:
    std::vector<Consumer>  m_consumers;
};

// in .t.cpp
class ConsumerMock
{
public:
    MOCK_METHOD0(start, int());
    MOCK_METHOD0(stop, int());
};

TEST(ConsumerTest, normalTest)
{
    // how should I set expect call here since Consumer Mock is internally created

    ConsumerGroup<ConsumerMock>  cgroup;
}

尽管存在构造函数,析构函数,开始,停止的定义,但仍然存在链接错误(ConsumerGroup中未定义开始,停止)。

我应该如何模拟在测试类中创建的对象?

0 个答案:

没有答案