Search code examples
unit-testinggoogletestgooglemock

Expectation with google mock


I would like to say the following with gmock:

Method A should be called twice, once with parameter X and the second time with parameter Y. Than the method should not be called again.

I know how to do the first part, but how i say that the method should never be called again?


Solution

  • {
      InSequence s;
      EXPECT_CALL(mock, Method("X"));
      EXPECT_CALL(mock, Method("Y"));
    }
    

    Once these two calls are received, further calls to Method will generate errors.