Unit Tests in UWP
Every well written code cannot exist without unit tests (of course you can stay on stand point that there is no better place to test your code than production environment, but I'm not trying to convince you ;)). In classic world of Windows desktop/web applications setup of working unit test framework was usually problem-free and instant. Unfortunately the reality in UWP turns out not so straightforward. Below I present you how MsTest, NUnit and XUnit frameworks behave with naked VS test runner and with Resharper 10 tests runner ... and without them. doh.
I've started the introduction of unit tests into project as usually - create empty Class Library project and install NUnit (3.2.0) - that part went smoothly but then first crash arrived - NUnit.Engine is not compatible yet with UWP apps - that results in that VS Test Runner is blind and doesn't see our tests and Resharper Runner throws exception related to the mentioned NUnit.Engine.
We can still run our tests from console but who wants to struggle with lack of debugging feature in VS? There is a workaround, it's not perfect but better than nothing. We have to install NUnit Templates for Visual Studio via VS Extensions
After that we can create project from NUnit 3 Test Project (Universal Windows) that hosts test runner in Universal UI application. Still we cannot run it via VS or Resharper test runners but now we can debug our code. Next disadvantage - we cannot run single test at once, always all of them. Below you can see beautiful NUnit 3.0 Test Window in which we can examine our test results.
As we see usage of NUnit with UWP is currently clumsy. That determines me to look for different framework and that's how we come to default unit tests runner provided by Microsoft - MsTests.
To create test project we simply navigate to create new project -> Visual C# -> Windows -> Universal and select Unit Test App (Universal Windows), and that is first and last step of setting unit tests environment, we can immediately start covering our existing (or not;)) source code.
MsTests looks much better we can run them via VS and Resharper without a problem. There is only one small obstacle, MsTests also base on standalone Universal UI Application so every tests run requires starting of UI application that slows down our tests.
This small obstacle has turned out too much annoying for me and has led me to XUnit - and that was bullseye. Setup of XUnit is not straightforward like in case of MsTest but it's well described step by step in documentation (https://xunit.github.io/docs/getting-started-uwp.html). In shortage: you have to create standard MsTest project and immediately throw away reference to MSTestFramework.Universal and install in its place two packages XUnit and XUnit.runner.visualStudio from nuget. Thats all if you want to run tests only via VS runner. In case of Resharper 10 we have to install add-on from Resharper Extensions.
As you probably could notice we didn't remove .xaml part of project, why? XUnit framework, to run properly, has to be hosted in application project and project requires entry point. But calm down it has no influence on our runners - UI application is not run like in case of standard MsTest so all tests goes quick and sweet.
Sample project with all three kinds of unit test frameworks you can find here