You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One thing, which might be useful when using templates is to avoid writing macros, though.
That can be done by defining an interface instead and using GMock, automatic mock injection and DI without loosing performance at all as it will be injected via templates.
OK, sounds good. I'm still trying to understand the first "automatic mock injection" part. Actually my question was more about the "automatic mock generation" part (e.g. avoiding macros), looks like it is possible as in the final example. So, at least we can define the interface in C++ (even if the concrete class doesn't inherit it) and avoid the MOCK_* macros (yay!).
Also just to check if I understand correctly, but in the final example then any mocks generated for IStreamJustForTesting will have dynamic dispatch (and use static_cast), but this only applies to the mocks and the production implementations do not need that interface? (and this is the price we pay -- at test time -- for avoiding the macros)
Activity
kris-jusiak commentedon Dec 18, 2017
Thanks @paulreimer for the questions
Can we still use the automatic mock generation?
And this automatic mocks injection when resolve a type T
return Mock<T>();Can we still use
GUnit.GMake? (since we are using derived class template args, notstatic_cast<iface&>)Boost.DI? (I know, a question for a different repo)Yes, no issues here
With templates no issues too
One thing, which might be useful when using templates is to avoid writing macros, though.
That can be done by defining an interface instead and using GMock, automatic mock injection and DI without loosing performance at all as it will be injected via templates.
paulreimer commentedon Dec 18, 2017
OK, sounds good. I'm still trying to understand the first "automatic mock injection" part. Actually my question was more about the "automatic mock generation" part (e.g. avoiding macros), looks like it is possible as in the final example. So, at least we can define the interface in C++ (even if the concrete class doesn't inherit it) and avoid the
MOCK_*macros (yay!).Also just to check if I understand correctly, but in the final example then any mocks generated for
IStreamJustForTestingwill have dynamic dispatch (and usestatic_cast), but this only applies to the mocks and the production implementations do not need that interface? (and this is the price we pay -- at test time -- for avoiding the macros)kris-jusiak commentedon Dec 18, 2017
Right, Macros might be avoided with interfaces and GMock.
Yes, exactly. No cost in production but dynamic dispatch in testing.