Dependency injection helps you unit test your code pretty well. But how do we test if the right dependencies are injected finally at run time ?? For example I have a service class which takes in a list of service validators. Since the list of validators is injected by a DI container, how do we make sure that the right validators are injected ?? What if some developer mistakenly removes a validator from the list. Even if we do write tests on the depen dency injection, we can't assert on all dependencies without breaking encapsulation. The only way is an integration test which asserts on the validation behaviour of the service. If the service behaviour is complicated, then it becomes difficult to write integration tests. Any ideas ??

Edit
Report