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?
I use Google Mock, so a specific answer would help as well.
In this case you should inject by pointer and not by reference, then you could pass a NULL pointer. This would work assuming you’re object is indeed a mock and not a fake object, therefore it has no real dependency on the injected object.
For
boost::shared_ptryou could do the following: