使用命令行运行本地的VS2012/C++ 64位单元测试

15

我正在尝试从命令行运行单元测试。我尝试使用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"
程序的响应是:
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 期望一个程序集而不是本地测试项目,这就是为什么它失败的原因。如果是这样,我该如何从命令行运行本地测试? 如果不是,请问我应该如何配置 mstest 才能正常工作呢?


3
这些测试是由vstest.executionengine.x86.exe执行32位版本,vstest.executionengine.exe执行64位版本。 - Hans Passant
1
你接近了 :) 我正在寻找的程序是vstest.console.exe,它隐藏在C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow中。你可以回答这个问题,这样我就可以接受它 :) - Spook
2个回答

25

感谢 Hans Passant 的指导。

解决方案是使用:

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


1
相同的可执行文件存在于vs2015中(路径中的11.0改为14.0)- 谢谢 - Caribou
对于 VS2017 Enterprise 版本:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" - kayleeFrye_onDeck

0
另一个选择是安装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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接