Michael MacDonald

Cucumber Formatters

In Testing on February 5, 2010 at 8:00 am

Cucumber allows you to format the results you get from running your features. With Cucumber 0.5, the Rails specific code was extracted out into a separate gem called cucumber-rails. With it came a smarter cucumber.yml file which now defaults to the “progress” format instead of “pretty”.

This change prompted me to take a closer look at the options available for formatting the output of running cucumber features. To see the full list enter in your console:

cucumber --help

To change the format pass either of the following:

cucumber --format FORMAT
cucumber -f FORMAT

Here’s some of the format options:

  • html – Generates an HTML version of your test results which you can save as a file and view in a browser. This is the one to use when running Cucumber inside Textmate.
  • pdf – Generates a fancy formatted pdf of your test results which you can share with your clients if you wish or for archiving in your company’s records management app.
  • pretty – This was originally the default format. It prints out each step of a scenario and colours it according to whether it passed, failed, was undefined or was skipped. This format provides you with the most information and is the one to use when working the red-green-refactor cycle.
  • progress – This is the new default. It prints a dot for each step that passed, an F for one that failed, a U for an undefined step, and a hyphen for a skipped step.
  • rerun – Prints out the failing features (with line numbers). This is now used in the default “smart” cucumber profile to setup an automatic rerun of failed scenarios. When you first use cucumber, it runs all features and scenarios. If any fail, a rerun.txt will be created that contains the output from the rerun format, a list of failed scenarios. Now when you run cucumber again, it will only run the failed scenarios instead of your entire collection of features.
  • tag_cloud – Useful for showing you what tags you have used and how often.
  • usage – Useful for revealing which step definitions have not been used and which are the slowest.

Finally, if none of these fit your needs, you can always write your own.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: