Google Mock:Return()一个值列表 [英] Google Mock: Return() a list of values

查看:587
本文介绍了Google Mock:Return()一个值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Google Mock的Return(),您可以返回在调用模拟函数时返回的值。但是,如果某个函数预计被调用多次,并且每次你想要返回不同的预定义值。

Via Google Mock's Return() you can return what value will be returned once a mocked function is called. However, if a certain function is expected to be called many times, and each time you would like it to return a different predefined value.

例如:

EXPECT_CALL(mocked_object, aCertainFunction (_,_))
    .Times(200);

每次返回 aCertainFunction 一个递增整数?

How do you make aCertainFunction each time return an incrementing integer?

推荐答案

使用序列

using ::testing::Sequence;

Sequence s1;
for (int i=1; i<=20; i++) {
    EXPECT_CALL(mocked_object, aCertainFunction (_,_))
        .InSequence(s1)
        .WillOnce(Return(i));
}

这篇关于Google Mock:Return()一个值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆