Search code examples
c++boostturtle-mock

Turtle Mock: How to ignore unexpected calls?


Is it possible to ignore unexpected method calls for Turtle Mock? During my test the mocked method is called multiple times. I want to check only one invocation with specific parameters per test. Now I have to write one enormous test where I have to write all method invocations.


Solution

  • The expectation selection algorithm describes how you can set multiple invocations:

    Each method call is then handled by processing the expectations in the order they have been defined :

    • looking for a match with valid parameter constraints evaluated from left to right
    • checking that the invocation count for this match is not exhausted

    So if you set the one you expect and a generic one such as

    MOCK_EXPECT( v.display ).once().with( 0 );
    MOCK_EXPECT( v.display );
    

    it should quiet the other calls while still making sure the one you care about will be fulfilled.

    Now if you wanted to enforce the order of the calls, for instance to make sure the one you’re interested in happens first, you would have to use a sequence, such as

    mock::sequence s;
    MOCK_EXPECT( v.display ).once().with( 0 ).in( s );
    MOCK_EXPECT( v.display ).in( s );