1

Is it possible to select test cases by SpecFlow tag in Microsoft Test Manager? And if so, how?

user2609980
  • 10,264
  • 15
  • 74
  • 143

1 Answers1

2

Tags in SpecFlow get translated into TestCategory attributes in the generated code. As far as I know (worked with MTM until a year ago) you can:

  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

With the last option, you can create with a bit of creativity a set of testplans with different tests sorted by test category. And I am afraid that is the best you can do without writing your own wrapper around MTM. The TestCategory information is available in TFS, but not exposed to the user in MTM.

EDIT

To clear things up after the comment.
Given this feature file:

@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

It gets generated to this code:

[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();
}

The scenario becomes a (by MSTest.exe) executable testmethod with three TestCategories: timtim, Jabberwocky and manxome. These are the same testcategories as mentioned in the articles. Coded UI does have a Test Category property that can be used to order the tests, but this category boiles down to using the same TestCategory attribute.

AutomatedChaos
  • 7,267
  • 2
  • 27
  • 47
  • Thanks. The kind of tags I meant was for example an `@Acceptance` on top of a scenario. E.g., `@Acceptance Given ... When ... Then ...` ([see other examples](https://decoupledlogic.wordpress.com/2013/12/17/specflow-tagging/)). The `TestCategory` seems like a special kind of attribute on top of CodedUI tests, not the scenario tags. So unfortunately your suggestion does not seem to work here. If I have more time I will try to find a way, your suggestions did give some inspiration into the capabilities of the tcm tool. – user2609980 Aug 27 '15 at 09:04
  • 1
    @ErwinRooijakkers I elaborated more on the test categories, if you look into the `.feature.cs` file yourself, you can see how your own tags become test categories. – AutomatedChaos Aug 28 '15 at 08:25
  • Thank You! I did not make the link, but now I see! :) – user2609980 Aug 29 '15 at 12:15