Unit Testing with UWP

This took me an entire day to figure out but I hope that this will help people out in the future.  Unit Testing on UWP with xUnit is downright easy via Visual Studio, but if you try to do it from the command line (say, for example, for CI) then you might run into a few hitches.

So, the generally accepted modern way to run tests from the command line (in the non .NET Core world) is to use vstest.console.exe .  This utility allows you to discover and run tests from the command line.  However, there are three things that prevent you from getting a UWP app up and running.

Problem #1: No tests are discovered.  This program is limited to finding tests within a .dll file.  However, if you have made a unit test project for UWP then all of your tests will be in a .exe file and fail to be found.  I had to hack around this by making a dll with the tests and having the UWP project reference that.  I haven’t confirmed that this still works inside of Visual Studio but I hope it does.

Problem #2: You cannot run an unauthorized UWP application.  You need to import that temporary signing key that gets generated with your application into your computer’s trust store.  See this stackoverflow post for more information on that (steps 3 and 4).

Problem #3: FileLoadException on all of your dlls.  This happens if you specify /TestAdapterPath in the command line arguments of the runner.  What happens is that it switches to desktop mode and can no longer run things properly.  I am not sure of the details but omitting that argument will fix it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s