Cucumber JVM Listing tags, names and description details from feature files without test execution

Introduction

In Cucumber there is no easy way to determine the mapping between tags and scenarios or vice versa. Similarly it is not a trivial task to collate the names and descriptions of features and scenario. This article introduces a custom plugin which collects the data and outputs to a file or console. For more information regarding Cucumber custom plugin refer to this article.

Source

The source code for this article is located here. A sample report is available here.

Plugin Details

The custom plugin runs by setting the dryRun value to true for CucumberOptions. This means that the data is collected without running any scenarios. The report displays the following data –

  • Feature uri, name and description
  • Background name and description
  • Scenario(Outline) uri, name and description
  • Step text, keyword and argument
  • Tag to Scenarios mapping
  • Scenario to Tags mapping
  • Scenarios without tags

An important point is that the plugin class has to be located in the cucumber.runtime.formatter package. The reason is that the plugin class uses the final TestSourcesModel class which is also has package protected access.

The output data is sent to the console or stored in a file. Below is the CucumberOptions for the runner which uses a file. A file named ‘report.log’ is created with the details.

@CucumberOptions (glue = "stepdef", dryRun = true, 
plugin = {"cucumber.runtime.formatter.FeatureFileDataFormatter:target/details" }, 
features = "src/test/resources/feature/")

To use a console for the data, remove the part after the class name starting from the colon.

For more information about creating a custom plugin refer to this article.

Tag To Scenario Mapping

There are three sections in the report regarding the mappings of tags and scenarios present in all the feature files. A sample is provided for the three sections.

First is the tags to scenarios mapping which lists all the scenario uri’s for a specific tag. For a scenario outline the line number of the “Scenario Outline” keyword is mentioned instead of the rows in the examples table.

Second is the scenarios to tags mapping, all the tags for a specific scenario are listed. The tags listed are cascaded.

Third section lists the scenarios which do not have any tags.

A complete report is available here.

Feature File Mapping

This report section lists out the details of the feature, background, scenario, scenario outline and step keywords present in all the feature files.

Attributes like name, description and uri are listed. For the step keyword the step text, keyword and arguments are listed.

A sample report highlighting the mapping using color codes is provided.

A complete report is available here.

Leave a Reply

Your email address will not be published. Required fields are marked *