I want to use Extract And Override pattern in my code, the pattern is:
Extract a method that creates an object needed in code make it virtual and override the methods in the TextFixture where it creates a fake stub object, I have read about this in The Art Of Unit Testing.
Now I finally found a place where this idea can be used but the method is called in the constructor of my object, and VS displays a warning saying that the constructor contains a virtual method, not I see why this might be a problem because it’s an easy way to break the code in the future.
My question is, does the benefits of testable code overshoot the problem that this might cause in the future?
This is a problem that TDD enthusiasts often solve using IoC- the idea is that rather than constructing the object being tested in the constructor, you pass it to the constructor using your IoC container. Then for tests, you configure your IoC container to use a mock object.