简体   繁体   English

为什么不建立我的UWP单元测试项目会生成测试dll

[英]Why doesn't building my UWP Unit Test project produce a test dll

I'm trying to run unit tests from the command line. 我正在尝试从命令行运行单元测试。 For this, I need the test dlls, as per this: https://msdn.microsoft.com/en-us/library/ms182490.aspx 为此,我需要测试dll,如下所示: https : //msdn.microsoft.com/en-us/library/ms182490.aspx

In the Prerequisites section on that page, it says I need to "Run a Unit Test and Fix Your Code" 在该页面上的“先决条件”部分中,提示我需要“运行单元测试并修复您的代码”

Question 1: Do I need to run tests from VS to be able to run them from command line? 问题1:我是否需要从VS 运行测试才能从命令行运行它们? Surely not? 当然可以吗?

Now to the more important bit. 现在到更重要的位置。 When I build my solution, regardless of whether it's via VS or command line using MSBuild, I do not get any dlls generated for my tests. 构建解决方案时,无论是通过VS还是使用MSBuild的命令行,都不会为测试生成任何dll。

I know this is for C++ but thought might still be relevant https://social.msdn.microsoft.com/Forums/vstudio/en-US/a89c2173-90e6-47b2-af8e-48865969cbca/msbuild15-does-not-create-a-dll-file-after-building-the-c-native-unit-test-project?forum=msbuild . 我知道这是针对C ++的,但认为可能仍然有用https://social.msdn.microsoft.com/Forums/vstudio/en-US/a89c2173-90e6-47b2-af8e-48865969cbca/msbuild15-does-not-create-一个dll文件在构建本机单元测试项目后?forum = msbuild (not that it helped of course). (这当然没有帮助)。

Question 2: Why don't my unit test dlls get generated when building? 问题2:构建时为什么不生成我的单元测试dll?

UWP is a bit different from other projects when it comes to Unit Testing. 在单元测试方面,UWP与其他项目有些不同。 Universal Windows Apps run in a sandbox to make sure they don't do things they don't have permissions for. 通用Windows应用程序在沙箱中运行,以确保它们不会执行其没有权限的操作。 For this reason, the unit test project is not a simple DLL only, but in fact a full-fledged UWP app (and the generated executable has appx extension), that is launched and performs the tests. 因此,单元测试项目不仅是一个简单的DLL,而且实际上是一个成熟的UWP应用程序(并且生成的可执行文件具有appx扩展名),可以启动并执行测试。

That said, you can still launch the unit test project from the console using a special command as you can see in this SO answer . 也就是说,您仍然可以使用特殊命令从控制台启动单元测试项目,如您在此SO答案中所见。

vstest.console.exe /Platform:x64 AppPackages\UnitTestProject1_1.0.0.0_x64_Debug_Test\UnitTestProject1_1.0.0.0_x64_Debug.appx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM