简体   繁体   中英

Running tests based on a namespace using vstest.console using

I have been using MsTest.exe to run tests using the namespace like this:

mstest.exe /testcontainer:"MyDllFile.dll" /test:"NameSpace.Folder.Folder1.*"

This worked like a charm but I needed to be able to pass parameters at runtime to my tests, so I found the *.runsetttings file and its capability to pass parameters to a test using RunTestParameters and getting them from the properties in the TestContext but the downside is that I have to be very specific as to what test(s) I want to run and have to give it the a specific method name or names separated by commas to execute the tests as it is shown below:

vstest.console.exe "MyDllFile.dll" /Settings:"my.runsettings" /Tests:"TestMethod1,TestMethod2"

I also tried the TestCaseFilter with no luck either:

vstest.console.exe "vstest.console.exe "MyDllFile.dll" /Settings:"my.runsettings" /TestCaseFilter:"TestCategory=MyTestCategory"

Does anyone one have a suggestion as to how can I accomplish what I was able to do with mstest.exe with vstest.console.exe?

Thanks!!

The documentation for vstest.console.exe is particularly poor. It is possible but neither the commandline help nor MSDN documentation explains how to do it.

The options available for the TestCaseFilter setting appear to be adapter specific but for the default MsTest adapter the following properties are available for filtering.

Name=<TestMethodDisplayNameName>
FullyQualifiedName=<FullyQualifiedTestMethodName>
Priority=<PriorityAttributeValue>
TestCategory=<TestCategoryAttributeValue>
ClassName=<ClassName> (Valid only for unit tests for Windows store apps, currently not available for classic MSTest)

..using the folling operators.

= (equals)
!= (not equals)
~ (contains or substring only for string values)
& (and)
| (or)
( ) (paranthesis for grouping)

So for your purposes a TestCaseFilter of the following form should suffice.

/TestCaseFilter:"FullyQualifiedName~ProjectNamespace.Subnamespace.TestClass"

More info and examples here http://blogs.msdn.com/b/vikramagrawal/archive/2012/07/23/running-selective-unit-tests-in-vs-2012-rc-using-testcasefilter.aspx

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