谷歌模拟多个EXPECT_CALL彼此冲突?

时间:2018-10-03 23:50:37

标签: c++ googletest conflict gmock

我有以下代码段,并且运行良好:

class If2{
public:
    virtual void set(const char* s)=0;
};
class Impl2:public If2{
public:
    MOCK_METHOD1(set, void(const char*));
};
TEST(t2,case2){
    Impl2 mock;
    EXPECT_CALL(mock,set).Times(Between(1,5));
    mock.set("aa");
}

但是当我为set()添加2个EXPECT_CALL时,它将不起作用:

TEST(t2,case2){
    Impl2 mock;
    EXPECT_CALL(mock,set).Times(Between(1,5));
    EXPECT_CALL(mock,set(Not(HasSubstr("bb"))));
    mock.set("aa");
}

错误消息是:

Actual function call count doesn't match EXPECT_CALL(mock, set)...
        Expected: to be called between 1 and 5 times
        Actual: never called - unsatisfied and active

对我来说真的很奇怪,我曾经叫过“设置”,为什么多个EXPECT_CALL在这里不起作用? 谢谢。

0 个答案:

没有答案