通过Microsoft Test Manager中的SpecFlow标记选择测试用例

时间:2015-08-24 14:46:25

标签: specflow microsoft-test-manager mtm

是否可以通过Microsoft Test Manager中的SpecFlow标记选择测试用例?如果是这样,怎么样?

1 个答案:

答案 0 :(得分:2)

SpecFlow中的标记在生成的代码中被转换为TestCategory属性。据我所知(直到一年前与MTM合作)你可以:

  1. Execute tests with MSTest filtered on TestCategory by Categories
  2. Execute tests with VSTest.Console filtered on TestCategory by TestCaseFilter
  3. Import test cases into MTM filtered on TestCategory
  4. 使用最后一个选项,您可以创建一组具有按测试类别排序的不同测试的测试计划。而且我担心如果不在MTM上编写自己的包装器,这是最好的。 TestCategory信息在TFS中可用,但不在MTM中向用户公开。

    修改

    在评论后澄清事项 鉴于此功能文件:

    @timtim
    Feature: MSTest Tags Test
        In order to get feedback at the right time
        As a test automation specialist
        I want to categorize my tests and run them accordingly
    
    @Jabberwocky @manxome
    Scenario: A test with tags
        Given 'twas brillig
        When gyre and gimble in the wabe
        Then all mimsy were the borogoves
    

    它生成此代码:

    [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
    [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("A test with tags")]  
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "MSTest Tags Test")]
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("timtim")]
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("Jabberwocky")]
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("manxome")]
    public virtual void ATestWithTags()
    {
        TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A test with tags", new string[] {
                    "Jabberwocky",
                    "manxome"});
        #line 8
        this.ScenarioSetup(scenarioInfo);
        #line 9
        testRunner.Given("\'twas brillig", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
        #line 10
        testRunner.When("gyre and gimble in the wabe", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
        #line 11
         testRunner.Then("all mimsy were the borogoves", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
        #line hidden
        this.ScenarioCleanup();
    }
    

    该方案成为(通过MSTest.exe)可执行测试方法,其中包含三个TestCategories:timtimJabberwockymanxome。这些是与文章中提到的相同的测试类别。 Coded UI does have a Test Category property可用于订购测试,但此类别可归结为使用the same TestCategory attribute