Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring Code Coverage for a UWP App

For a standard CSharp/UWP App, is there a good way to measure Unitest code coverage? It looks like Visual Studio tools do not apply for UWP. My end goal is to get an objective measurement for how thorough our testing is, and to watch for regressions on coverage.

like image 850
Scott Henry Avatar asked Mar 21 '16 22:03

Scott Henry


1 Answers

I have gotten code coverage to work for the following configuration, using VS2015:

  • Create a Portable Class Library (PCL) project.
  • In Project Properties, re-target the project to .NETStandard1.4 (see the official compatibility matrix for why to choose v1.4).
  • Reference the PCL project from your UWP app.
  • For the test project, use xUnit and a .NET Core class library, setting it up as described in the xUnit docs.

If you can minimize the amount of code in your UWP app project (e.g., by using the MVVM pattern), then most of your tests will be against the PCL. Since code coverage works against a .NET Standard library set up as shown, your numbers will be fairly accurate even if you can't measure coverage against the UWP app project itself.

(Of course, this is more practical for new apps than existing apps, since it requires a particular design).

like image 111
RedGreenCode Avatar answered Oct 04 '22 03:10

RedGreenCode