Cycle 2.5 introduces the ability to filter tags during Feature and Playlist execution. This allows the Cycle user more control over which Scenarios within a Feature or Playlist are executed while also allowing more flexibility when assigning tags to Scenarios during Feature writing.
Previously, Cycle users were able to specify a tag or list of tags to be marked for execution. Any Scenarios with matching tags would be executed regardless of any additional tags that might be associated with the Scenarios.
Multiple tags could be marked for execution in a Feature or Playlist and the list of tags would be executed using OR logic. For example, if I select tags "tagA", "tagB", and "tagC" for execution, then any Scenarios tagged with "tagA" OR "tagB" OR "tagC" would be executed.
In addition to the existing functionality using OR logic on a list of tags, tag filtering available in Cycle 2.5 allows Cycle users to filter tags as required for execution or excluded from execution.
These new options allow for greater control over which tests are executed or excluded during Feature and Playlist execution and provide the ability to have targeted test runs that can meet specific testing requirements.
Tags can be filtered as required for execution or excluded from execution by adding one of two available filters to the tag name when building the tag list.
A combination of tags with filters and tags without filters can be added to the list of tags for a Feature or Playlist to control exactly which test Scenarios will be executed.
Filters are not required on tags in the list of tags to be executed.
If no filters are included, the list of tags will be evaluated using OR logic. This means any scenarios that include any of the specified tags will be executed.
The example below would execute any scenarios tagged with "tagA" OR "tagB" OR "tagC".
Adding a "+" filter before the tag name indicates that a Scenario must be tagged with that tag in order to be executed.
Any Scenarios that do not include the specified tag will be ignored during the test run regardless of other tags on assigned to the Scenarios. To use the filter, simply type "+" before typing the tag name.
The example below would execute any Scenarios tagged with "tagA" as long as the Scenarios are also tagged with "tagB". Any scenarios tagged with "tagA" that are not also tagged with "tagB" would be ignored during the test run.
Adding a "-" filter before the tag name indicates that any Scenario tagged with the specified tag will be excluded from execution.
Any Scenario that includes the specified tag will be ignored during the test run. To use the filter, simply type "-" before typing the tag name.
The example below would execute any Scenarios tagged with "tagA" unless the Scenario is also tagged with "tagC". Any Scenario tagged with "tagA" that is also tagged with "tagC" would be ignored during the test run.
Tag filters can also be used with cycle-cli. You can use a combination of tags with and without filters in your cycle-cli command. However, you should always keep in mind the behavior of the "+" and "-" filters when including unfiltered tags in your tag list.
NOTE: You should include the entire tag list within double quotes to ensure the cycle-cli command is parsed properly. If not, the command may be interpreted incorrectly if any tags are preceded by a "-", and you may receive unintended cycle-cli execution results.
Example cycle-cli command using tag filters:
The next section of this article provides an example Feature that includes several Scenarios using simple math steps available within Cycle. Each Scenario has been tagged with multiple tags that apply to the math function being tested. Example tag lists and the expected Scenarios to be executed by those lists is included below the example Feature.
Feature: Tag Examples Feature
@all_math_tests
@addition_test
@positive_number_result
Scenario: Addition Scenario 1
And I assign 5 to variable "number"
And I increase variable "number" by 5
And I echo $number
@all_math_tests
@addition_test
@negative_number_result
Scenario: Addition Scenario 2
And I assign -10 to variable "number"
And I increase variable "number" by 3
And I echo $number
@all_math_tests
@subtraction_test
@positive_number_result
Scenario: Subtraction Scenario
And I assign 10 to variable "number"
And I decrease variable "number" by 6
And I echo $number
@all_math_tests
@multiplication_test
@negative_number_result
Scenario: Multiplication Scenario
And I assign 5 to variable "number"
And I multiply variable "number" by -6
And I echo $number
Examples of tag lists that could be applied to the example Feature and the Scenarios that would run as a result of those tag lists are detailed below:
Tag List:
No tags provided
Scenarios Executed:
ALL Scenarios Executed
Tag List:
all_math_tests
Scenarios Executed:
ALL Scenarios Executed
Tag List:
all_math_tests, +addition_test
Scenarios Executed:
Addition Scenario 1, Addition Scenario 2
Tag List:
all_math_tests, +addition_test, -negative_number_result
Scenarios Executed:
Addition Scenario 1
Tag List:
all_math_tests, -positive_number_result
Scenarios Executed:
Addition Scenario 2, Multiplication Scenario
Tag List:
addition_test, subtraction_test
Scenarios Executed:
Addition Scenario 1, Addition Scenario 2, Subtraction Scenario
Tag List:
+addition_test, +subtraction_test
Scenarios Executed:
NO Scenarios Executed