The SpecFlow+ Runner is out of maintenance. Read more about it here.

Filter

The <Filter> element allows you to define filters that are applied to your tests, allowing you to determine which tests to execute. Filters can also be defined in <Target> elements, in which case the filter only applies to that target. Filters defined outside of a <Target> element are applied globally. The Test Explorer window in Visual Studio only lists those tests that meet your filter criteria (after rebuilding your project). Note that global filters also apply when running tests by right-clicking on a feature file and selecting Run SpecFlow Scenarios.

Filters can be applied to tests based on tags (including regular expressions), or the scenario or feature name.

Note: Tags and filters are case-sensitive.

The following filter types can be defined:

Prefix Type Description
@ Tag Matches a tag exactly, e.g. '@MyTag' only returns those tests with the '@MyTag' tag.
tagmatch: Tag Matches tags by regular expression, e.g. 'tagmatch:Tag[1-3]' matches tests with the tags 'Tag1', "Tag2' or 'Tag3'.
testpath:Feature: Test Matches tests by feature name. You can use the * wildcard in feature names, e.g. testpath:Feature:Calcu* matches the features "Calculator" and "Calculus".
Note: Replace spaces in scenario names with the plus character (+) in your filter. Example:
Replace Buy a book with Buy+a+book.
testpath:Scenario: Test Matches tests by scenario name. You can use the * wildcard in scenario names, e.g. testpath:Scenario:*+two+numbers matches the scenarios "Add two numbers", "Subtract two numbers" and "Multiply two numbers".
Note: Replace spaces in scenario names with the plus character (+) in your filter. Example:
Replace Buy a book with Buy+a+book.
testpath:target: Target Matches tests by target. You can use the * wildcard in scenario names, e.g. testpath:Target:Chrom* matches the targets "Chrome" and "Chromium".
Note: Replace spaces in scenario names with the plus character (+) in your filter. Example:
Replace 32-bit envrionment with 32-but+environment.

You can combine filters using logical operators. The following operators are supported:

  • |: OR
  • &: AND (however you need to use &amp; instead in the profile, as it is an XML file)
  • !: NOT

Examples

Filter

<Filter>@MyTag &amp; @YourTag</Filter> executes all tests with both the @MyTag and @YourTag tags.<Filter>!tagmatch:Tag[1-9]</Filter> executes all tests that are not tagged with any of @Tag1 to @Tag9.<Filter>@MyTag | tagmatch:tag[1-9]</Filter> executes all tests with either the @MyTag tag or tags @Tag1 to @Tag9.

Target with Filter

<Targets>
   <Target name="IE_11">
      <Filter>@MyTag</Filter>
   </Target>
    <Target name="FireFox">
      <Filter>@MyTag</Filter>
   </Target>
    <Target name="Chrome">
      <Filter>@MyTag</Filter>
   </Target>
</Targets>