Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a single test case from MSTEST

Tags:

mstest

I am using MStest to run a single test case but could not find a correct command

I tried:

1)mstest.exe /testcontainer:testproject.dll /test:MethodTest1 This run all the test case starting from name MethodTest1. I have other test name Like MethodTest100, MethodTest101

2)mstest.exe /testcontainer:testproject.dll /test:MethodTest1 /unique This needs to pass Test Namespace name and Test Class name.

It works when i execute following but i have only access to Test Method not to class or namepsace mstest.exe /testcontainer:testproject.dll /test:TestNamespace.TestClass MethodTest1 /unique

I would appreciate if somebody could help me in exact command to run a single test case without using Class Name or Name pace in which TestMethod Lies.

Thanks

like image 531
sam_33 Avatar asked Sep 29 '10 20:09

sam_33


People also ask

How use MSTest command line?

Use the command MSTest from the command prompt. The MSTest command expects the name of the test as parameter to run the test. Just type MSTest /help or MSTest /? at the Visual Studio command prompt to get help and find out more about options.

How can an individual unit test method be executed or debugged?

Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T). If individual tests have no dependencies that prevent them from being run in any order, turn on parallel test execution in the settings menu of the toolbar.

How do I run unit test from console?

run Visual Studio unit tests by using MSTest.exe, located at %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe in my case. using /testcontainer:Path\To\Your\TestProjectAssembly. dll to indicate where your tests are coded. You can specify multiple '/testcontainer' options if required.


Video Answer


2 Answers

For running multiple tests under a given class or namespace, you can use a wild card *. 

 

So, running:

mstest.exe /testcontainer:testproject.dll /test:TestNamespace.TestClass.*

 

will work

like image 53
Jerry F Avatar answered Sep 29 '22 20:09

Jerry F


A test case name only needs to be unique within the context of a test class, and a test class name only needs to be unique in the context of a test namespace. Therefore, when you want to run a single test (by name) you always have to also supply the names of the containing namespace and class. Otherwise, MSTest is not able to uniquely identify the test you want to have run.

like image 31
kroonwijk Avatar answered Sep 29 '22 19:09

kroonwijk