如何使用VS2017的Vstest.console.exe运行VS2015测试?
Hey there! Let's work through this error you're seeing when running vstest.console.exe—since MsTest works fine, we know your tests themselves are valid, so the issue is likely with how vstest.console is finding the necessary test providers. Here are actionable steps to fix this:
Specify the Test Adapter Path explicitly
vstest.consolerelies on test adapters (like the MsTest adapter) to discover and run tests. If the built version from GitHub isn't picking up the adapter automatically, point it directly to the VS2015 MsTest adapter directory. Run this command instead:"c:\VSTest\vstest\src\vstest.console\bin\Debug\net451\win7-x64\vstest.console.exe" "c:\mydll.dll" /TestAdapterPath:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\TestWindow\Extensions"The path above is the default location for VS2015's MsTest adapter—adjust it if your VS installation is in a different directory.
Use VS2015's Built-in vstest.console.exe
The version you built from GitHub might be incompatible with VS2015's test framework. Try using thevstest.console.exethat comes bundled with your VS2015 installation instead. Run this command:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "c:\mydll.dll"This is the same runtime that MsTest uses under the hood, so it should work if MsTest runs your tests successfully.
Verify Test DLL Compatibility
Ensure your test DLL targets a .NET framework version compatible with thevstest.consolebuild you're using (you're using thenet451version). Check your test project's properties in VS2015: go to Project Properties > Application > Target framework and confirm it's set to .NET Framework 4.5.1 or lower.Check for Discoverable Tests
Make sure your test DLL actually contains discoverable tests. Run this command to list all tests in the DLL:"c:\VSTest\vstest\src\vstest.console\bin\Debug\net451\win7-x64\vstest.console.exe" "c:\mydll.dll" /ListTestsIf no tests show up, double-check that your test classes have the
[TestClass]attribute and test methods have[TestMethod]attribute—these are required for MsTest-based tests to be discovered.Try Building vstest.console in Release Mode
Debug builds can sometimes have missing or incomplete components. Rebuild thevstest.consoleproject in Release configuration, then use the Release version executable (found atc:\VSTest\vstest\src\vstest.console\bin\Release\net451\win7-x64\vstest.console.exe) to run your tests.
内容的提问来源于stack exchange,提问作者vivek singh

