【问题标题】:Running native VS2012/C++ 64-bit unit tests from command line从命令行运行本机 VS2012/C++ 64 位单元测试
【发布时间】:2012-11-28 12:05:59
【问题描述】:

我正在尝试从命令行运行单元测试。我尝试使用以下命令使用 mstest.exe 程序:

E:\VS Projects\...\>"C:\Program Files (x86)\Microsoft Visual Studio 11.0\
    Common7\IDE\MSTest.exe" /testcontainer:mytest.dll 
    /testsettings:"E:\VS Projects\...\Local.testsettings"

mstest 程序的响应是:

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

Loading E:\VS Projects\...\Local.testsettings...
Loading mytest.dll...
mytest.dll
Unable to load the test container 'mytest.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:///E:\VS Projects\...\mytest.dll' or one of its dependencies. The 
module was expected to contain an assembly manifest.

Local.testsettings 确实包含测试应在 64 位环境中运行的信息。

我可以猜到,mstest 需要一个程序集而不是本机测试项目,这就是它失败的原因。如果是这样,我如何从命令行运行 native 测试?否则,我应该如何配置 mstest 才能正常工作?

【问题讨论】:

  • 32 位版本由 vstest.executionengine.x86.exe 执行,64 位版本由 vstest.executionengine.exe 执行。
  • 你很接近 :) 我正在搜索的程序是隐藏在 C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow 中的 vstest.console.exe。你可以回答这个问题,这样我就可以接受了:)

标签: c++ unit-testing dll mstest native


【解决方案1】:

感谢 Hans Passant 的指导。

解决方法是使用:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe

【讨论】:

  • vs2015 中存在相同的可执行文件(上面路径中是 14.0 而不是 11.0) - 谢谢
  • 对于 VS2017 企业版:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
【解决方案2】:

另一个选项是安装Catch2,它允许您从命令提示符以 exe 的形式运行单元测试项目并显示结果:

https://github.com/catchorg/Catch2

C:\Projects\T9Predict\T9PredictTests\Debug\> T2PredictTests.exe
T2PredictTests.exe

C:\Projects\T9Predict\T9PredictTests\T2PredictTests.cpp(33): FAILED!
  REQUIRE( result[0] == "hello" )
with expansion:
  "" == "hello
===============================================================================
test cases: 2 | 1 passed | 1 failed
assertions: 2 | 1 passed | 1 failed

【讨论】:

    猜你喜欢
    • 2011-03-18
    • 2013-04-07
    • 2013-09-01
    • 2014-03-20
    • 2011-04-25
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    相关资源
    最近更新 更多