Google Mock: multiple expectations on same function with different parameters

后端 未结 2 420
走了就别回头了
走了就别回头了 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:27

    By default gMock expectations can be satisfied in any order (precisely for the reason you mention -- so you don't over specify your tests).

    In your case, you just want something like:

    EXPECT_CALL(foo, DoThis(1));
    EXPECT_CALL(foo, DoThis(2));
    EXPECT_CALL(foo, DoThis(5));
    

    And something like:

    foo.DoThis(5);
    foo.DoThis(1);
    foo.DoThis(2);
    

    Would satisfy those expectations.

    (Aside: If you did want to constrain the order, you should use InSequence: https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#expecting-ordered-calls-orderedcalls)

提交回复
热议问题