Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 359
angela d Avatar asked Dec 27 '11 19:12

angela d


People also ask

How do you mock a Gtest method?

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.

What is Expect_call Gtest?

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).

Does Gtest include gMock?

gMock is bundled with googletest.

What is gMock?

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).


1 Answers

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.

like image 144
BЈовић Avatar answered Sep 20 '22 08:09

BЈовић