Search code examples
c#unit-testingwindows-phone-8.1caliburn.microcaliburn

Unit testing in Windows phone/store apps


I am working on a Windows Phone/Store and a Windows 10 UWP app. I am trying to understand what are some good techniques to unit test.

I have the unit test project setup and i have written a few unit tests. I am using CaliburnMicro framework and i have setup constructor injection which in turn helps me in unit testing as i have interfaces defined.

Is it a good practice to test Internal APIs? For example, say i have a service that checks for NetworkInfomation and gives me appropriate results or a battery check service? Would be good to test these?

Also, i use Background Transfer Service and background Task as well. Would it be feasible to test the upload scenarios ?

New to unit testing, so any help appreciated.


Solution

  • I also use Caliburn.Micro in my code but I don't think it should matter most MVVM frameworks work the same. I use Moq for my a mocking framework which works really well with dependency injection.

    Problems with Moq is in conjunction with Caliburn is that Caliburn uses a lot of extension functions which is difficult to impossible to Verify

    Abstract as far as possible and avoid testing implementation details, in short test behavior and make an abstraction of implementation detail such as NetworkInfomation and Background Transfer Service.

    public class GolldysNetworkInfomation : INetworkInfomation
    {
       NetworkInfomation networkInformation;
    }
    
    public class SystemUnderTest
    {
        public SystemUnderTest(INetworkInfomation networkInfomation)
        {
        }
    }
    

    You can now use INetworkInfomation to simulate your NetworkInfomation during unit testing, and allows you to create other implementations of the INetworkInfomation.

    There are two schools of thought about unit testing:

    1. Classical
    2. Mockist

    You can look at Classical vs Mockist approach to better understand.

    Hope this helps.