简体   繁体   中英

how to run an mstest dll from command line

anybody knows how to run unit test dlls built using mstest from the command line, without running VS

considering that on the machine there is .net 4.0 and VS2010 installed

I haven't done it myself, but I'd imagine that using the mstest command line is the way forward... if you've already tried that and had problems, please give more details.

mstest /testcontainer:path\to\tests.dll

EDIT: As noted in comments, you should either do this after putting the right directories on the path, or include the full path to mstest.exe.

Quick Answer : Examples

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

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

Note

Because the test assembly file resides in a different folder, a relative path is necessary,

If you are using test lists, it is best to use the /testmetadata option together 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

Detailed :

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 2010, point to Visual Studio Tools, and then click 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

Note

To change the folder to which the command prompt window opens by default, click Start, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, right-click Visual Studio Command Prompt (2010), and then click Properties. In the Visual Studio Command Prompt (2010) 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:

:\\Documents and Settings\\\\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:

:\\Documents and Settings\\\\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.

Source: http://msdn.microsoft.com/en-us/library/ms182487(v=vs.100).aspx

尝试这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM