gpt4 book ai didi

c++ - 针对 Visual Studio 2012 native C++ 测试从命令行运行 mstest

转载 作者:IT老高 更新时间:2023-10-28 12:52:54 25 4
gpt4 key购买 nike

我有一个带有许多 native C++ 测试项目的 Visual Studio 2012 解决方案。我可以使用测试资源管理器选项卡在 Visual Studio 2012 中正确并成功地运行所有这些。

但是,从命令行运行时,我无法运行测试。

按照文档,我一直在运行以下命令行

mstest /testcontainer:PathToTestProject\Win32\Release\testproject.dll

我也需要跑

mstest /testcontainer:PathToTestProject\x64\Release\testproject.dll

用于测试64位版本的代码。

当我运行这些命令行时,我收到以下错误消息。

Microsoft (R) Test Execution Command Line Tool Version 11.0.50727.1 Copyright (c) Microsoft Corporation. All rights reserved.

Loading PathToTestProject\Win32\Release\testproject.dll... PathToTestProject\Win32\Release\testproject.dll Unable to load the test container PathToTestProject\Win32\Release\testproject.dll' or one of its dependencies. If you build your test project assembly as a 64 bit assembly, it cannot be loaded. When you build your test project assembly, select "Any CPU" for the platform. To run your tests in 64 bit mode on a 64 bit processor, you must change your test settings in the Hosts tab to run your tests in a 32 bit process. Error details: Could not load file or assembly 'file:///c:\PathToTestProject\Win32\Release\testproject.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

代码是原生 c++,有两种构建配置,一种在 Win32 平台上,另一种在 x64 平台上。我不能有 AnyCPU 平台配置。为了能够从命令行运行测试,我在这里缺少什么?

最佳答案

找了好久,终于发现了一个很隐蔽的msdn文档页面 here它说明了 mstest 与不同测试项目类型的兼容性。事实证明,mstest 与 native 单元测试不兼容(msdn 很高兴在一个容易找到的位置记录这一点)。相反,对于 native 单元测试项目,您需要使用运行的 Visual Studio 测试 (vstest.console.exe) 而不是 msbuild。

例如

vstest.console.exe /Platform:x64 PathToTestProject\x64\Release\testproject.dll

关于c++ - 针对 Visual Studio 2012 native C++ 测试从命令行运行 mstest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15086380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com