Unit-test a controller that has a Dependency Injection in MVC
I am trying to unit test a controller that already has开发者_开发技巧 a constructor dependency injection. How do I also pass the dependency injection to the unit test? I am using the Ninject to do the DI in the controller but I have never unit tested anything so this is new for me.
Normally, you pass constructor dependencies manually from your unit test. This allows you to test a small piece of your software by passing in mocks or doubles of the dependencies. We have a fairly large system and have never needed to use our injection framework for a unit test.
The injection framework is used for production and for integration tests where you are wiring together many components.
精彩评论