Visual Studio supports many testing features, and provides an IDE for testing and running the tests as explained in previous chapters. It is very simple to run tests from Test Explorer user interface and view the results, or re-run the test from the Test Results window. Other than the IDE support, Visual Studio provides command line options to execute or run the tests that were created using the IDE. This option is very handy when executing the tests from other applications, or scheduling automated testing.
In this chapter, multiple command line tools are explained in detail to use for running the tests with different options and then collecting the output. Visual Studio 2012 provides three different command line utilities to execute the tests and they are as follows:
VSTest.Console
: This command line utility is for running the automated unit tests and coded UI tests from the command line.MSTest
: This command line utility is for running the automated tests, viewing Test Results from Test Runs, and saving the results to Team Foundation Server. MSTest
is also used for the compatibility with Visual Studio 2010.TCM
: This command line utility is used for importing automated tests into Test Plan, running tests from Test Plan, and viewing lists of test items.In Visual Studio 2012, the VSTest.Console
command line utility is used for running the automated unit test and coded UI test. VSTest.Console
is an optimized replacement for MSTest
in Visual Studio 2012.
There are multiple options for the command line utility that can used in any order with multiple combinations. Running the command VSTest.Console /?
at the command prompt shows the summary of available options and the usage message. These options are shown in the following screenshot:
Running the test from the command prompt requires the expected parameters to be passed based on the options used along with the command. Some of the options available with VSTest.Console
command are explained in the next few sections:
This command is used to select particular tests from the list of tests in the test file. Specify the test names as parameters to the command, and separate the tests using commas when multiple tests are to be run. The next screenshot shows a couple of test methods that run from the test file:
The output shows the Test Run result for each of the tests along with the messages, if any. The summary of the tests is also shown at the end of the results sections with the time taken for the test execution.
This command is used to list all available tests within the test file. The following screenshot lists the tests from one of the Test Project file:
The next one is another command line utility, MSTest
, which is used to run any automated tests.
52.15.245.1