As we know, the unit testing tools has been completely revamped in Visual Studio 2011. One such component is the new command line runner – vstest.console.exe
What is it ?
new command line test runner “vstest,console.exe” which would run tests written against any test framework – MSTest framework, Nunit, Xunit and so on.
Where can I find it ?
vstest.console.exe could be invoked from directly from “Visual Studio Command Prompt”. The executable would be found under “Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow” folder. Vstest.console.exe /? would give more details on the various switches provided by the test runner.
How is it different from Mstest.exe ?
With Visual Studio 2011, the tests written using visual studio unit test framework could be run using either vstest,console.exe or using mstest.exe. The behavior would be same with subtle differences (which is briefed in the below table).
vstest.console.exe has some additional options /platform /framework which would let the user to run their tests in a specific platform/framework to increase test coverage.
Mstest and Vstest:
Below is a brief summary on the various switches provided by Mstest.exe and the equivalent switches in vstest.console.exe
There is no switch needed in front of the input test assembly in vstest.console.exe unlike mstest.exe.
Mstest /testcontainer :abc.dll /testcontainer:xyz.dll
Vstest.console.exe abc.dll xyz.dll
Inv stest.console.exe /testcasefilter switch handles filtering based on all categories like priority , test category and so on.
Mstest /testcontainer:abc.dll /minpriority:1
Vstestabc.dll /testcasefilter:"Priority=1 | priority=2"
VSMDI file is deprecated in Visual Studio 2011 and there is no equivalent switch for this.
Vstest.console.exe accepts the run settings in two formats:
Mstest.exe /testcontainer:abc.dll /testsettings:nightly.testsettings
Vstest.console.exe abc.dll /settings:nightly.testsettings
If the default location of results need to be overriden user need to pass this value using a runsettings file.
Mstest.exe /testcontainer:abc.dll /results:C:\Results.trx
Vstest.console.exe abc.dll /settings:output.runsettings where the context of the .runsettings file would be something like below :
<?xml version="1.0" encoding="UTF-8"?>
Mstest.exe /testcontainer:abc.dll /test:API
Vstest.console.exe abc.dll /tests:API
In Visual Studio 2011, the command line runner runs tests in no isolation mode by default. Hence no switch is needed explictly.
/inisolation switch could be specified explicitly to force isolation if required.
Note : Though the default behavior is to run in process, if the input test assembly requires isolation (like needed a different .net platform or different architecture of the test runner, tests would be run in isolation)
Mstest.exe /testcontainer:abc.dll /noisolation
Vstest.console.exe doesn’t create the TRX file by default.
Results would be sent only to console. If TRX is needed, user has to enable it explicitly by specifying /logger:trx
Mstest.exe /testcontainer:abc.dll /noresults
Vstest.console.exe abc.dll /logger:trx
Vstest.console.exe prints the stack trace and error message of each test to the console by default.
Hence there is no equivalent of /detail switch
Mstest.console.exe /testcontainer:abc.dll /detail:errormessage /detail:errorstacktrace
/pulish and the related options
Vstest.console.exe doesn’t expose any functionality to publish results to TFS
There is no equivalent switch to unique. But the functionality could be achieved specifying the fully qualified name of the test.