首页 > 解决方案 > google mock 多个 EXPECT_CALL 相互冲突?

问题描述

我有这个代码片段,它运行良好:

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

对我来说真的很奇怪,我已经调用了一次“set”,为什么多个 EXPECT_CALL 在这里不起作用?谢谢。

标签: c++googletestconflictgmock

解决方案


推荐阅读