What should be the strategy of unit testing when using IoC?

后端 未结 4 1756
说谎
说谎 2021-02-12 23:29

After all what I have read about Dependency Injection and IoC I have decided to try to use Windsor Container within our application (it\'s a 50K LOC multi-layer web app, so I ho

4条回答
  •  醉话见心
    2021-02-13 00:11

    I've just written a very similar style and size app. I wouldn't put any dependency injection in the unit tests because it is not complicated enough to be necessary. You should use a mocking framework to create your mocks (RhinoMocks / Moq).

    Also Automocking in Moq or the Auto Mock Container in Rhinomocks will simplify building your mocks further.

    Auto mocking allows you to get object of the type you want to test without setting up mocks by hand. All dependencies are mocked automatically (assuming they are interfaces) and injected into the type constructor. If you need to you can set up expected behavior, but you don't have to.

提交回复
热议问题