Pages

Tuesday, January 25, 2011

Cucumber Tutorial - Tagging

After a few months, scenarios and features in a project can become unwieldy. With hundreds of feature files, we might not want to run everything all the time. Even without that, it is often useful to be able to check just a subset of the features, for example skip running one or two very slow tests to get faster feedback.

Cucumber allows us to manage large groups of scenarios easier with tags. Tags are free-form text comments assigned to a scenario, that provide meta-data about the type, nature or group of that scenario. You can assign tags to a scenario by putting it before the scenario header, adding an ‘at’ sign (@) before the tag name.

For example:
 
 @slowtest 
 Scenario: end-to-end signup 
 ... 

You can execute only the scenarios with a particular tag using the --tags option, for example: 
cucumber --tags @fasttest 

Another option is to skip only the scenarios without a particular tag. For 
that, prefix the tag with a tilde (~). Here is an example: 
cucumber --tags ~@slowtest 

No comments:

Post a Comment