如何在Visual Studio中对Windows 10应用程序进行单元测试?

Luk*_*tko 18 unit-testing win-universal-app visual-studio-2015

如何在Visual Studio 2015中对Windows 10应用程序进行单元测试?

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

在此输入图像描述

Gor*_*ium 25

右键单击您的解决方案并选择Add > New Project.然后选择Unit Test App (Windows Universal).确保您没有选择Unit Test LibraryUnit Test Project.它必须是环球影片.这应该生成一个基类供您使用.

您可能希望添加对主项目的引用.要执行此操作,请右键单击您的测试项目Add > Reference,然后选择然后选择您的主项目.您现在应该能够从主项目中创建要测试的类.


gim*_*ael 6

我可以理解这种混淆 - Visual Studio团队在其他方面并不是很好的项目层次结构决策.

正常的方法是将测试项目放在下面Test.由于不明原因,他们决定Unit Test App (Universal Windows)直接放置Windows -> Universal并因此绕过常识.

综上所述; 为测试项目Windows -> Classic Desktop,并Web放置下Test.测试项目Windows -> Universal放在Windows -> Universal.