Search code examples
unit-testingxamarindependency-injectionmvvm-lightportable-class-library

Effects of dependency injection on PCL based unit test case


In the xamarin project there is PCL and all the logic lies there with the help of MVVMlight over there.

But I have a need to add depedency injection to run something on the respective platforms but I am wondering will it affect unit-test case on PCL ?

If it affects how it can worked around

Somebody kindly explain this


Solution

  • Depending on whether you use DI when running your tests or not it will effect the tests.

    Imagine, you are mocking some interface, you register it in the IoC container and use it in one test. Then you imagine that you are running tests in parallel. If one of the other tests that you are running require or do something with that registered mocked interface, it may or may not yield the results you want.

    Hence, in test scenarios, you would probably prefer not to use IoC but manually create instances and pass them onto the classes you are testing, such that they are not shared between tests.