【问题标题】:Running tests based on a namespace using vstest.console using使用 vstest.console 运行基于命名空间的测试
【发布时间】:2016-01-06 23:10:00
【问题描述】:

我一直在使用 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 所做的事情?

谢谢!!

【问题讨论】:

    标签: c# automation mstest vstest.console.exe


    【解决方案1】:

    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

    【讨论】:

    • 谢谢!我会试试这个。我
    • TestClass 在上面的例子中是 CONTAINS。 /TestCaseFilter:"FullyQualifiedName~ProjectNamespace.Subnamespace.TestClass" 将匹配该子命名空间中以“TestClass”开头的任何测试。
    猜你喜欢
    • 2014-08-23
    • 2015-12-25
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多