How can I unit test a Windows 10 app in Visual Studio 2015?
I created a Blank App Universal Windows project and added a new Unit Test Project to the solution, but when I try to add a reference to my UWP app in the Test Project, I get an error saying 'Unable to add a reference to project "Project Name"'.
Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
Select the test project in Solution Explorer. On the Project menu, select Add Reference. In Reference Manager, select the Solution node under Projects. Select the code project you want to test, and then select OK.
Right click on your solution and choose Add > New Project
. Then select Unit Test App (Windows Universal)
. Make sure that you don't select Unit Test Library
or Unit Test Project
. It must be the Universal one. This should generate a base class for you to work with.
You'll probably then want to add a reference to your main project. To do this, right click on your test project and select Add > Reference
and then choose your main project. You should now be able to create classes from your main project to test.
I can understand the confusion - the Visual Studio team is not consistent in there otherwise fine project hierarchy decisions.
Normal approach was to place Test projects under Test
. For reasons unknown, they decided to place the Unit Test App (Universal Windows)
directly under Windows -> Universal
and hereby bypassing common sense.
In summary; Test projects for Windows -> Classic Desktop
and Web
is placed under Test
. Test projects for Windows -> Universal
is placed under Windows -> Universal
.
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