How to run unit testing tests from command line?

两盒软妹~` 提交于 2019-11-28 18:32:36
Nam G VU

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.

Christopher Maddock

For number 4. To run all tests in an assembly it's simply:

mstest /testcontainer:YourCompiledTestAssembly.dll

For question 

5 All tests except the ones marked as category [TestCategory("some-category")]

Use  

mstest.exe /testcontainer:yourTests.dll  /category:"!some-category"

If you need to exclude more than one category, use

  

mstest.exe /testcontainer:yourTests.dll  /category:"!group1&!group2"

Reference:  /category filter 

You might be interested by the Gallio bundle. It provides a free common automation platform to run your tests (MSTest, MbUnit, NUnit, xUnit, etc.) with various test runners (GUI, command line, PoSh, plugins for 3rd party tools, etc.)

In particular you may want to use Gallio.Echo which is a nice command line test runner:

The Gallio test runners have also filtering capabilities to run a subset of your unit tests only (e.g. per category, per fixture, etc.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!