Running database unit tests from the command-line

Since database unit tests are first-class test types in Team Test, you can take full advantage of the MSTest.exe command-line tool for running and automating the execution of your database unit tests.


First you need to get yourself into a command prompt with MSTest.exe in your path. The easiest way to do this is to open the Visual Studio 2005 Command Prompt from your Start menu under Microsoft Visual Studio 2005 -> Visual Studio Tools.


Then you need to decide what scope of tests you would like to run from the command-line. MSTest allows you to choose from the following:


Test list in a solution

Running a given list of tests in a solution is the recommended approach to running a collection of tests. You can define the list of tests inside the Test Manager. The Test Manager is only available if you have Team Test along with Team Data or the entire Team Suite. To learn how to create test lists, check out this article:


Once you have defined your test list, you can run your test list from the command-line by specifying the test metadata file and the name of the test list. The test metadata file is automatically generated inside any solution containing tests. This file contains the details of the test lists that have been defined.


The command-line to run my SprocTests test list in my SachNorthwind solution would look like the following:

(I assume here your current path is at the solution folder level)


MSTest /testmetadata:SachNorthwind.vsmdi /testlist:SprocTests


Entire test project

You can also run all the tests contained within a test project. To do this, you need to specify the compiled dll that is generated for your test project.


This would look like the following:


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


Individual test

To run an individual test in a test project, you can do either of the following.


MSTest /testmetadata:SachNorthwind.vsmdi /test:CustOrderHistTest


MSTest /testcontainer:SachNorthwindTests\bin\debug\SachNorthwindTests.dll /test:CustOrderHistTest


For more information on MSTest and supported command-line options, go here:


Sachin Rekhi