c++qtgooglemockqtestlib

How can I control when my gmock is verified?


Using 'another test framework' (Qt), I want to control when the google mocks are verified:

void MyQtTest::test_ThisAndThat() {
     MyMock mock;
     EXPECT_CALL(mock, foo(1));

     system_under_test.bar();

     //VERIFY_EXPECTATIONS(mock)
 }

But I don't find anything about that in the Cookbook.


Solution

  • This is what i normally do in similar situations:

    void MyQtTest::test_ThisAndThat()
    {
        MyMock mock;
        EXPECT_CALL(mock, foo(1));
        system_under_test.bar();
    
        Mock::VerifyAndClearExpectations(&mock);
    }
    

    Reference: https://github.com/google/googletest/blob/master/docs/gmock_cheat_sheet.md#verifying-and-resetting-a-mock

    edit: fixed broken link

    2nd edit: fixed broken link again