How to run dll mstest from command line

does anyone know how to run unit test dlls built with mstest from command line without starting VS

considering that .net 4.0 and VS2010 are installed on the machine


source to share

3 answers

I have not done this myself, but I would assume that using the command line mestest is the way forward ... if you have already tried this and had problems, please provide more details.

mstest /testcontainer:path\to\tests.dll


EDIT: As noted in the comments, you must either do this after setting the correct directories in the path, or include the full path to mstest.exe.



Quick answer: Examples

You must use the / testcontainer parameter along with the / category parameter to select which tests will run the categories in. The following command, for example, runs in the solution folder and runs those tests that are in the Priority 1 and ShoppingCart categories:

MSTest /testcontainer: testproject2\bin\debug\testproject2.dll /category:"Priority1&ShoppingCart"



Since the test build file is in a different folder, a relative path is needed,

If you are using test lists, it is better to use the / testmetadata parameter in conjunction with the / testlist parameter. For example, the following command is executed in the solution folder. Since the test metadata file is also in this folder, the path is not required:

MSTest /testmetadata:Bank.vsmdi /testlist:balancetests


In detail:

Running tests from the command line

1. Open a Visual Studio command prompt.

To do this, click the Start button, select All Programs, Microsoft Visual Studio 2010, Visual Studio Tools, and Visual Studio Command Prompt (2010).

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

: \ Program Files \ Microsoft Visual Studio 10.0 \ VC


To change the folder in which the default Command Prompt window opens, click the Start button, select Microsoft Visual Studio 2010, select Visual Studio Tools, right-click Visual Studio Command Prompt (2010) and select Properties ". In the Visual Studio Command Line Properties (2010) dialog box, you can change the default folder path in the Start box.

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

To define the solutions folder, first define the Visual Studio projects folder. To do this, click Options on the Tools menu in Visual Studio, and then select Projects and Solutions. In the Visual Studio Projects section, you see the path, for example:

: \ Documents and Settings \\ My Documents \ Visual Studio \ Projects

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

: \ Documents and Settings \\ My Documents \ Visual Studio \ Projects \ Bank

3. Run the MSTest.exe program.

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

If necessary, specify the path to the folder where the metadata file or test container is located. The test metadata files are located in the solution folder.

Depending on the test type, test containers are XML files, assemblies generated from test projects, or other files that reside in the test project folders.





try it

mstest.exe /testcontainer:c:\projects\MyTests\Sampe.Tests.dll




All Articles