Question

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
Was it helpful?

Solution

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

OTHER TIPS

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.

Use Exactly(0) for all your class methods.

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

You can also use StrictMock instead of NiceMock. This will fail on any "uninteresting" call, i.e., whenever a method of the mock is called, but no EXPECT_CALL was defined.

See Google Mock documentation here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top