How to mock templated methods using Google Mock?

In previous version of Google Mock you can only mock virtual functions, see the documentation in the project’s page. More recent versions allowed to mock non-virtual methods, using what they call hi-perf dependency injection. As user @congusbongus states in the comment below this answer: Google Mock relies on adding member variables to support method mocking, … Read more

google mock – can I call EXPECT_CALL multiple times on same mock object?

Yes, you can call EXPECT_CALL on the same mock object multiple times. As long as you assure that all EXPECT_CALL were called before the mocked methods were actually used. Otherwise your test will rely on undefined behavior. From ForDummies: Important note: gMock requires expectations to be set before the mock functions are called, otherwise the … Read more

Can Google Mock a method with a smart pointer return type?

A feasible workaround for google mock framework’s problems with non (const) copyable function arguments and retun values is to use proxy mock methods. Suppose you have the following interface definition (if it’s good style to use std::unique_ptr in this way seems to be more or less a philosophical question, I personally like it to enforce … Read more

Is Google Mock a good mocking framework? [closed]

I use it frequently. It’s trivial to do relatively easy things, and possible to do very difficult things – that’s pretty much what I want from a framework. The hardest part about writing custom Matchers (and other stuff) with Google’s mocks isn’t Google’s mocks, it’s C++’s template errors… they’re close to impossible to parse. I … Read more

gmock setting default actions / ON_CALL vs. EXPECT_CALL

There are subtle but significant differences between the two statements. EXPECT_CALL sets expectation on a mock calls. Writing EXPECT_CALL(mock, methodX(_)).WillRepeatedly(do_action); tells gMock that methodX may be called on mock any number of times with any arguments, and when it is, mock will perform do_action. On the other hand, ON_CALL(mock, methodX(_)).WillByDefault(do_action); tells gMock that whenever methodX … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)