C++ – Running mstest from command line against Visual Studio 2012 native C++ tests

cmstestvisual studio 2012

I have a Visual Studio 2012 Solution with a number of native c++ test projects.
I can run all of these correctly and successfully from within Visual Studio 2012 using the Test Explorer tab.

However, I cannot get the tests to run when running from the command line.

Following the documentation I have been running the following command line

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

I also need to run

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

for the testing of the 64bit version of the code.

When I run these command lines I get the following error message.

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.

The code is native c++ and has two build configurations one on Win32 platform, and the other on x64 platform. I cannot have an AnyCPU platform configuration.
What am I missing here to be able to run the tests from the command line?

Best Answer

After a lot of searching, I finally discovered a very hidden msdn documentation page here which states the compatibility of mstest with different test project types. And it turns out the mstest is not compatible with native unit tests (nice of msdn to document this in an easy to find location). Instead you need to use the visual studio test running (vstest.console.exe) instead of msbuild for native unit test projects.

for example

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