Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to speed up unit testing in Visual Studio 2015 for UWP

When testing a Windows Universal class library (.NET 4.6) in Visual Studio 2015, the time required in the "red->green->refactor" cycle is quite long. My test project is just the standard MSTest "Unit Test App" project. Even in the simplest scenario of a brand new solution, brand new subject and test projects, and a basic int Add(int n1, int n2) method, it's taking about 8-15 seconds. This is the time (after making a small code change) from clicking "run test" till the pass/fail is shown.

On my machine (Win 10 pro) conducting the same experiment but with a WPF-based solution yields about 1-2 seconds.

In the UWP scenario, the actual test time itself is listed as 79 ms. The rest of the time is compiling and deploying the unit test app container.

Is there any way to significantly speed up TDD with UWP?

like image 214
BCA Avatar asked Sep 18 '15 16:09

BCA


People also ask

How do I run a unit test boost Visual Studio?

Create a Boost. cpp file for your tests, right-click on the project node in Solution Explorer and choose Add > New Item. In the Add New Item dialog, expand Installed > Visual C++ > Test. Select Boost. Test, then choose Add to add Test.


1 Answers

The reason the TDD cycle takes so long is because all UWP code has to run in an AppContainer, and that requires packaging and deployment which is slow.

The way around this problem is to separate as much of your code as you can into a different project that doesn't need to run in an AppContainer and then test that project instead.

The solution for this is to use a portable class library for your application logic instead of a UWP class library. You'll find the portable class library in the new project dialog:

enter image description here

The default settings should work:

enter image description here

You then need to add a reference from the UWP to the portable library so you can consume it. To test the portable library, use a regular non-UWP unit test project:

enter image description here

Note - to make this work you'll need to change the target framework of the unit test project from 4.5.2 (which is the default) to 4.6.

Any unit test you run from the regular unit test project will run as fast as possible because it doesn't need to run in the AppContainer. I tested this out and the inner loop speed was great. Hope that helps!

like image 138
Michael Braude Avatar answered Sep 18 '22 22:09

Michael Braude