使用gmock返回模拟方法参数

Sajmplus

如何将模拟方法参数作为ON_CALL Return()动作参数返回?

模拟方法:

MOCK_METHOD1(foo, int(const std::string&))

测试:

TEST_F(Test, t) {

    //I'm using parametrized tests, this is only for simplicity
    std::map<std::string, int> results = {{"Apple", 1}};

    ON_CALL(obj, foo(_))
        .WillByDefault(
            Return(results.at(argument_from_foo_method)));
}
Sajmplus

我发现,使用Invoke动作:

ON_CALL(obj, foo(_))
        .WillByDefault(
            Invoke([&](const std::string &s) -> int { return results.at(s); });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章