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:
- A specific test (ie. a test written by a method marked [TestMethod()])
- All tests in a class
- All impacted tests of the current TFS p开发者_如何学编程ending change of mine.
- All tests
- 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:
- the MSTest.exe http://msdn.microsoft.com/en-us/library/ms182487.aspx
- the MSTest.exe's detailed options http://msdn.microsoft.com/en-us/library/ms182489.aspx
- obtaining the result http://msdn.microsoft.com/en-us/library/ms182488.aspx
[Edit]
After a while, I found the below useful tips.
- 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. - 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)
Currently I can have some answers for my needs:
A specific test (ie. a test written by a method marked
[TestMethod()]
)
UseMSTest.exe
/container:
TheAssemblyContainingYourSpecificTest/test:
TheSpecificTestNameAll tests in a class
UseMSTest.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.
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.)
** adding this due to errors I've encountered. To run all just use '''vstest.console.exe .\x64\Release\UnitTesting.dll''' vstest.console.exe is not deprecated so you will not need the /nologo suppression.
If needed it also has --TestCaseFilter|/TestCaseFilter:
精彩评论