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

angela d picture angela d · Dec 27, 2011 · Viewed 27.8k times · Source

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

Answer

BЈовић picture BЈовић · Dec 27, 2011

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.