如何将模拟方法参数作为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)));
}
我发现,使用Invoke
动作:
ON_CALL(obj, foo(_))
.WillByDefault(
Invoke([&](const std::string &s) -> int { return results.at(s); });
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句