Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run unit testing tests from command line?

I googled and found the below helpful references. Currently I want to run all from the command-line (for easy of execution & quickness) in cases:

  1. A specific test (ie. a test written by a method marked [TestMethod()])
  2. All tests in a class
  3. All impacted tests of the current TFS pending change of mine.
  4. All tests
  5. All tests except the ones marked as category [TestCategory("some-category")]

I'm not sure how can I write a correct command for my needs above.

References:

  1. the MSTest.exe http://msdn.microsoft.com/en-us/library/ms182487.aspx
  2. the MSTest.exe's detailed options http://msdn.microsoft.com/en-us/library/ms182489.aspx
  3. obtaining the result http://msdn.microsoft.com/en-us/library/ms182488.aspx

[Edit]

After a while, I found the below useful tips.

  1. run Visual Studio unit tests by using MSTest.exe, located at %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe in my case.
  2. using /testcontainer:Path\To\Your\TestProjectAssembly.dll to indicate where your tests are coded. You can specify multiple '/testcontainer' options if required.
  3. using /test:TestFilter to filter the tests to run. Note that this filter is applied to the full test method name (ie. FullNamespace.Classname.MethodName)
like image 692
Nam G VU Avatar asked Oct 14 '10 05:10

Nam G VU


People also ask

How do I run a unit test from command line in Python?

The command to run the tests is python -m unittest filename.py . In our case, the command to run the tests is python -m unittest test_utils.py .


1 Answers

Currently I can have some answers for my needs:

  1. A specific test (ie. a test written by a method marked [TestMethod()])
    Use MSTest.exe /container:TheAssemblyContainingYourSpecificTest /test:TheSpecificTestName

  2. All tests in a class
    Use MSTest.exe /container:TheAssemblyContainingYourClass /test:TheClassNameWithFullNamespace
    Note that the /test: is the filter which uses the full name of the class when filtering.

The others are still left unknown. Please disscuss if you know how.

like image 195
Nam G VU Avatar answered Sep 25 '22 12:09

Nam G VU