Just trying to inject unit testing into a system like brownfield. Keep in mind that I'm relatively new to the world of unit testing. Of course, this will be a gradual migration, because there are so many areas of pain.
The current problem I'm trying to solve is that we followed a lot of bad practices from our VB6 days and converting our application to .Net. We have many common / static functions that call other common functions, and others call others, etc. Sometimes defendations are passed as parameters, and sometimes they are just created in the calling function. I have already instructed our developers to stop creating common functions and instead create member instances and use only those member members from the interfaces, but this does not ease the current situation. Thus, you must recursively go through each dependency at the top level for each function of your code, and the method signatures turn into a mess.
I hope this is what the IOC will fix. We are currently using NUnit / Moq, and I am starting to explore StructureMap. So far, I understand that you pretty much tell StructureMap for the x interface. I want to use the specific y class by default:
ObjectFactory.Initialize(x=>{x.ForRequestType<IInterface>().TheDefaultIsConcreteType<MyClass>()});
Then at runtime:
var mytype = ObjectFactory.GetInstance<IInterface>();
IOC container initializes the correct type for you. Not sure how to change the fake to a specific type, but hopefully it's simple. Again, the IOC will solve the problems that I mentioned above? Is there a specific IOC structure that will do this better than StructureMap, or whether they can handle this situation. Any help would be greatly appreciated.
source share