Chapter 10. The Command Line

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.

VSTest.Console utility

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:

VSTest.Console utility

Running tests using VSTest.Console

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:

The /Tests option

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 /Tests option

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.

The /ListTests option

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 /ListTests option

Option

Description

/help

This option displays the usage message for all parameters type /? or /h.

/nologo

This option disables the display of startup banner and the copyright message.

/testcontainer:[file name]

This option loads a file that contains tests; multiple test files can be specified to load multiple tests from the files, for example:

/tescontainer:mytestproject.dll

/testcontainer:loadtest1.loadtest

/maxpriority:[priority]

/minpriority:[priority]

This option execute the tests with priority less than or equal to the value:

/minpriority:0 /maxpriority:2.

/category

This filter is used to select tests and run, based on the category of each test. We can use logical operators (& and !) to construct the filters, or we can use the logical operators (| and &!) to filter the tests.

/category:Priority1 – any tests with category as priority1.

/category: "Priority1&MyTests"– any tests with multiple categories as priority1 and Mytests.

/category: "Priority1|Mytests" – Multiple tests with category as either Priority1 or MyTests.

/category:"Priority1&!MyTests" – Priority1 tests that do not have category MyTests.

/testmetadata:[file name]

This option loads a metadata file. For example, /testmetadata:testproject1.vsmdi.

/testsettings:[file name]

This option uses the specified test settings file. For example, /testsettings:mysettings.testsettings.

/resultsfile:[file name]

This option saves the Test Run results to the specified file. for example,

/resultsfile:c: empmyresults.trx.

/testlist:[test list path]

The test list to run as specified in the metadata file; you can specify this option multiple times to run more than one test list. For example,

/testlist:checkintests/clientteam.

/test:[file name]

This is the name of a test to be run; you can specify this option multiple times to run more than one test.

/unique

This option runs a test only if one unique match is found for any given /test.

/noisolation

This option runs a test within the MSTest.exe process. This choice improves Test Run speed, but increases risk to the MsTest process.

/noresults

This option does not save the Test Results in a TRX file; the choice improves Test Run speed, but does not save the Test Run results

/detail:[property id]

This parameter is used for getting value of additional property along with the test outcome. For example, the following command with the property is to get the error message from the Test Result:

/detail:errormessage

The next one is another command line utility, MSTest, which is used to run any automated tests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.245.1