Mocking classes with dependency injection

646 views
Skip to first unread message

Jonathan

unread,
Apr 21, 2011, 4:46:37 AM4/21/11
to Google C++ Mocking Framework
I've asked the following question here:
http://stackoverflow.com/questions/5726580/mocking-c-classes-with-dependency-injection

Say you're testing class A and it has a dependency injection of B
which has a dependency injection of C.
So you mock B but the only constructor it has requires an injection of
C, so do you have to mock C as well and inject the mocked C into the
mocked B and only then inject it to A?
What if you have 5 consecutive dependancies?

What are the alternatives?

Jonathan

unread,
Apr 21, 2011, 6:36:43 AM4/21/11
to Google C++ Mocking Framework
Mike Long gave a good example of how to work around the problem on
StackOverflow using an interface.
Could it be at all possible for Google Mock framework to to have a
feature where when creating MockB, it would automatically create a
subclass of B (e.g. Btag) and with an empty constructor (it's a mock
after all) and have MockB inherit from it?

This would simplify the use of Google Mock in these cases, which in
fact may be quite frequent if you practice dependency injection.

I understand how this might go against C++ syntax, but there are some
macro geniuses out there, so it's worth a shot asking.

On Apr 21, 10:46 am, Jonathan <jonathan.li...@gmail.com> wrote:
> I've asked the following question here:http://stackoverflow.com/questions/5726580/mocking-c-classes-with-dep...
Reply all
Reply to author
Forward
0 new messages