Using IoC for Unit Testing

前端 未结 4 2110
一个人的身影
一个人的身影 2020-11-22 12:13

How can a IoC Container be used for unit testing? Is it useful to manage mocks in a huge solution (50+ projects) using IoC? Any experiences? Any C# libraries that work well

4条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 12:47

    How can a Ioc Container be used for unit testing?

    IoC will enforce programming paradigms that will make unit testing in isolation (i.e. using mocks) easier: use of interfaces, no new(), no singletons...

    But using the IoC container for testing is not really a requirement, it will just provide some facilities e.g. injection of mocks but you could do it manually.

    Is it useful to manage mocks in a huge solution (50+ projects) using IoC?

    I'm not sure what you mean by managing mocks using IoC. Anyway, IoC containers can usually do more than just injecting mocks when it comes to testing. And if you have decent IDE support that makes refactoring possible, why not using it?

    Any experience?

    Yes, on a huge solution, you need more than ever a non error-prone and refactoring-adverse solution (i.e. either through a type safe IoC container or good IDE support).

提交回复
热议问题