Google Mock: multiple expectations on same function with different parameters

后端 未结 2 421
走了就别回头了
走了就别回头了 2021-01-12 02:40

Consider the case where a certain mocked function is expected to be called several times, each time with a different value in a certain parameter. I would like to validate t

2条回答
  •  长发绾君心
    2021-01-12 03:29

    If you expect a function, DoThing, to be called with many different parameters, you can use the following pattern:

    for (auto const param : {1, 2, 3, 7, -1, 2}){
        EXPECT_CALL(foo, DoThing(param));
    }
    

    This is particularly helpful if your EXPECT_CALL includes many parameters, of which only one is changing, or if your EXPECT_CALL includes many Actions to be repeated.

提交回复
热议问题