3

我一直在使用 MsTest.exe 使用这样的命名空间运行测试:

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

这就像一个魅力,但我需要能够在运行时将参数传递给我的测试,所以我找到了 *.runsetttings 文件以及它使用 RunTestParameters 将参数传递给测试并从 TestContext 的属性中获取它们的能力,但是缺点是我必须非常具体地说明我想运行什么测试,并且必须给它一个特定的方法名称或用逗号分隔的名称来执行测试,如下所示:

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

我也尝试了 TestCaseFilter 也没有运气:

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

有没有人建议我如何使用 vstest.console.exe 完成我对 mstest.exe 所做的事情?

谢谢!!

4

1 回答 1

4

vstest.console.exe 的文档特别差。这是可能的,但命令行帮助和 MSDN 文档都没有解释如何做到这一点。

TestCaseFilter 设置可用的选项似乎是特定于适配器的,但对于默认的 MsTest 适配器,以下属性可用于过滤。

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)

..使用以下运算符。

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

因此,出于您的目的,以下形式的 TestCaseFilter 就足够了。

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

更多信息和示例在这里http://blogs.msdn.com/b/vikramagrawal/archive/2012/07/23/running-selective-unit-tests-in-vs-2012-rc-using-testcasefilter.aspx

于 2016-03-07T14:19:08.677 回答