17

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"'.

enter image description here

1
  • I think you should be adding a "Unit Test App (Universal Windows)" project
    – SepehrM
    Aug 13, 2015 at 12:09

3 Answers 3

24

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.

5

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.

0

Try RT-Clicking on a function name & see if there is a "Create Unit Tests" option on the context menu. For some reason adding a new unit test project is buggy, but the context menu worked for me.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.