google mock : how can I " EXPECT " that no method will be called on a mock

35,545

Solution 1

Create a StrictMock; any unexpected method call will be a failure.

Solution 2

There are no needs to explicitly tell that no methods will be called. If you set the logging level high enough, you should get a message if a method is called (if no expectation is set).

Other then that, you can set expectations like this :

EXPECT_CALL( mockObj, Foo(_) ).Times(0);

on all methods.

Solution 3

Use Exactly(0) for all your class methods.

the cardinality will be set to zero so you are expecting no calls

Share:
35,545
angela d
Author by

angela d

Updated on February 23, 2021

Comments

  • angela d
    angela d about 3 years

    I want to test the in case of some fail no method will be called on a mock object , using google mock. so the code be something like:

    auto mocObj = new MockObj;
    EXPECT_NO_METHOD_CALL(mocObj); //this is what I'm locking for
    
    auto mainObj = new MainObj(mocObj , ......and other mocks); // here I simulate a fail using the other mock objects, and I want to be sure the no methods are called on the mockObj