【问题标题】:How to cover multiple test cases in one automation script如何在一个自动化脚本中覆盖多个测试用例
【发布时间】:2014-12-25 18:28:59
【问题描述】:

在许多情况下,我发现为每个小测试用例编写脚本是多余的。如何使用 Microsoft VS 编写可以测试多个测试用例的脚本,并将结果报告给 Microsoft MTM 中的每个关联测试用例,而无需单独运行每个测试用例。例如,我有一个是/否/取消对话框弹出,并且有一个测试用例来验证这三个案例中的每一个。所有这三种情况都可以在一个脚本中进行验证。是否可以将每个测试用例与同一个脚本相关联,并通过只运行一次脚本来获得向每个测试用例报告的结果?

【问题讨论】:

    标签: c# testing automation case


    【解决方案1】:

    您可以使用 MSTest.exe 或 VSTest.console.exe 通过命令行运行 TestMethods。可以在批处理文件中调用 MSTest.exe 或 VSTest.console.exe。

    分配用户定义的 testcategory 属性来对您的测试进行分组。请参考Defining Test Categories to Group Your Tests。例如

    [TestCategory("Nightly"),
     TestCategory("Weekly"), 
     TestCategory("ShoppingCart"), 
    TestMethod()]
    public Void DebitTest()
    {
    }
    
    [TestCategory("Nightly"),
     TestCategory("Weekly"), 
     TestCategory("ShoppingCart"), 
    TestMethod()]
    public Void CreditTest()
    {
    }
    
    [TestCategory("Nightly"),
     TestCategory("Daily"), 
     TestCategory("ShoppingCart"), 
    TestMethod()]
    public Void BVTTest1()
    {
    }
    
    [TestCategory("Nightly"),
     TestCategory("Daily"), 
     TestCategory("ShoppingCart"), 
    TestMethod()]
    public Void BVTTest2()
    {
    }
    

    通过 TestCategory 的 VSTest.Console.exe 组运行测试

    Vstest.console.exe myTestProject.dll /TestCaseFilter:”TestCategory=Nightly"
    

    按测试类别按 MSTest.exe 组运行测试

    mstest /testcontainer:MyTestprojectName.dll /category:"Nightly"
    mstest /testcontainer:MyTestprojectName.dll /category:"Daily"
    

    请参阅MSDN Link 了解本主题中的更多命令行选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2017-07-12
      • 2017-12-24
      • 2016-05-26
      • 2019-03-24
      • 1970-01-01
      相关资源
      最近更新 更多