I need to UnitTest a Class Library (Universal Windows)
, but from the "Add New Project" windows, I just see this:
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With