Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to UnitTest a Class Library (Universal Windows) without testing a whole application?

I need to UnitTest a Class Library (Universal Windows), but from the "Add New Project" windows, I just see this:

enter image description here

This project runs all tests with the App Container, it always opens an App. Since I don't need all that overhead, I would like to know if is there a way to Unit Test just the UWP library.

like image 991
Francesco Bonizzi Avatar asked Dec 06 '15 23:12

Francesco Bonizzi


2 Answers

The quick answer is that if you need to test UI related classes you'll need to use this kind of "unit test". However if you have logic which you want to test - extract it to a portable library (PCL) and test it independently using plain old unit testing framework.

like image 151
Dror Helper Avatar answered Oct 05 '22 11:10

Dror Helper


Now that Portable Class Libraries - now called "Class Library (Legacy Portable)" in Visual Studio - are "legacy", I think the answer to this question has changed slightly.

If you want to write unit tests for non-UI-related logic of your UWP app, pull it out into a .NET Standard Class Library. A UWP app can reference a .NET Standard 2.0 class library without issues.

To actually test a Class Library (.NET Standard) you'll need to create an NUnit/xUnit/MSTest Project (.NET Core) and add a reference to your Class Library (.NET Standard).

I wrote a short blog post on this today once I got my solution working.

like image 34
jakejgordon Avatar answered Oct 05 '22 11:10

jakejgordon