Export (0) Print
Expand All

How to: Run Tests from the Command Line

You use the executable program MSTest.exe to run tests from the command line. This program can run any tests that can be automatically run, that is, any tests other than manual tests.

To run tests from the command line

  1. Open a Visual Studio command prompt.

    To do this, click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and then click Visual Studio Command Prompt.

    By default, the Visual Studio command prompt opens to the following folder:

    <drive letter>:\Program Files\Microsoft Visual Studio 8\VC

    NoteNote

    To change the folder to which the command prompt window opens by default, click Start, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, right-click Visual Studio 2005 Command Prompt, and then click Properties. In the Visual Studio 2005 Command Prompt Properties dialog box, you can change the path to the default folder in the Start in box.

  2. Either change directory to your solution folder or, when you run the MSTest.exe program in step 3, specify a full or relative path to the metadata file or to the test container.

    To identify your solution folder, first identify the Visual Studio Projects folder. To do this, click Options on the Tools menu in Visual Studio, and then click Projects and Solutions. Under Visual Studio projects location, you see a path such as the following:

    <drive letter>:\Documents and Settings\<user name>\My Documents\Visual Studio\Projects

    Your solution folder is typically a child of this Projects folder, such as the Bank folder in the following example:

    <drive letter>:\Documents and Settings\<user name>\My Documents\Visual Studio\Projects\Bank

  3. Run the MSTest.exe program.

    When you run MSTest.exe, you must specify either a test metadata file or a test container, using either the /testmetadata option or the /testcontainer option, respectively. You use the /testmetadata option only once, to indicate one test metadata file. You can use the /testcontainer option multiple times, to indicate multiple test containers.

    If necessary, include the path to the folder in which the metadata file or test container resides. Test metadata files reside in the solution folder.

    Depending on the test type, test containers are XML files, assemblies built from test projects, or other files that reside in the folders of a test project. For more information, see Test Containers.

Examples

It is best to use the /testmetadata option in conjunction with the /testlist option. The following command, for example, is run in the solution folder. Because the test metadata file also resides in that folder, no path is necessary:

MSTest /testmetadata:Bank.vsmdi /testlist:balancetests

The following command is also run in the solution folder. But because it references a test container, an assembly, that resides in a different folder, a path is required. This command runs all tests in the specified test container:

MSTest /testcontainer:testproject2\bin\debug\testproject2.dll

Optionally, you can use other MSTest command-line options for purposes such as specifying individual tests to run, publishing test data, and customizing screen output. For more information about these options, see MSTest.exe Command-Line Options.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft