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
Define a derived class like so: class B : public A { public: MOCK_METHOD0(isTrue, bool()); using A::doSomething; }; This obviously only works if isTrue is virtual . Beware: Check your company's testing guidelines regarding "code made especially for testing" instead of testing the real code.
EXPECT_CALL not only defines the behavior, but also sets an expectation that the method will be called with the given arguments, for the given number of times (and in the given order when you specify the order too).
gMock is bundled with googletest.
gMock is a library (sometimes we also call it a “framework” to make it sound cool) for creating mock classes and using them. It does to C++ what jMock/EasyMock does to Java (well, more or less).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With