15
votes

I'm attempting to run unit tests from the command line. I tried using the mstest.exe program using the following command:

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"

The mstest program responce was:

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 does include information, that the tests shall be run in 64-bit environment.

I can guess, that mstest expects an assembly instead of native test project and this is why it fails. If so, how can I run native tests from the command line? In the other case, how shall I configure the mstest to work properly?

2
Those tests are executed by vstest.executionengine.x86.exe for the 32-bit version, vstest.executionengine.exe for the 64-bit version.Hans Passant
You were close :) The program I was searching for was vstest.console.exe hidden in C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow. You may answer the question, such that I can accept it :)Spook

2 Answers

24
votes

Thanks for Hans Passant for guidance.

The solution is to use:

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

0
votes

Another option is to install Catch2 which allows you to run the unit testing project as an exe from the command prompt and display the results:

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