Top New Features of Cucumber JVM v6

Advanced Topics, Getting Started — August 6, 2021

Behavior Driven Development or BDD is one of the magical terms that many organizations are looking for today. The influence of the BDD methodology has significantly impacted the way the development model works. Its powerful business-driven approach has helped many teams collaborate with different stakeholders to define a better requirement.

One of the well-known tools that help to automate the requirements for the BDD projects is Cucumber. In this article, you will learn about some of the coolest features available as part of Cucumber 6 (cucumber-jvm) & previous versions and how you can leverage them with your automation pack and business discussions.

First, the basics!

For people who are new to Cucumber, the Gherkin language is simple English (or localised) statements put together to make a sensible requirement. It is written in Given-When-Then-But-And format.

The business requirements or the acceptance criteria are written as Scenarios, containing the Gherkin format requirements. Parameterising the scenarios with various combinations are achieved using Scenario Outlines with examples. All these Scenarios are written in a Cucumber feature file in the Cucumber framework.

A sample for a typical feature file is given below:

Rules & Examples:

One of the major features released in cucumber-jvm 6.0.0 is the usage of the Rule keyword. Although it is not a new feature to Cucumber, as it was released first in the cucumber-ruby 4.x and Gherkin 6.0. It’s an optional keyword, but can be very powerful in some business cases.

In general, the Rule keyword will help the team members to think of the scenarios as examples of acceptance criteria or business rules. Examples are different types of scenarios in which the requirement has to be mapped.

This feature will be very useful during the three amigos session, especially for the product owners and to provide better living documentation. The best example for real-time usage can be like this:

Other useful “Keywords”:

Apart from the Rules keyword, many keywords allow the business stakeholders to define the right set of requirements.

Some of them are:

  • Ability: To provide details on the ability of the feature or module
  • Business Need: What is the business requirement for the feature or module
  • Scenario Template: Defines a scenario of a requirement
  • Scenarios: Contains more examples for a defined scenario

The keywords are interchangeable as follows:

High-Level RequirementFeature, Ability, Business Need
ScenarioScenario Outline, Scenario Template
Combinations / ParametersExamples, Scenarios

Though there are new keywords introduced to the Feature file, the way of writing the step definitions remains the same. Cucumber can automatically deduct the scenarios and examples. You can see the step definitions for the above example here.

A sample for Ability, Scenario Template & Scenarios:

Online Cucumber Reports:

This is one of the coolest features available as part of Cucumber to date. You can now view Cucumber reports online with a link generated after every execution. The reports show the test results and act as living documentation. The online reports will be published via the https://reports.cucumber.io site with a unique URL provided in the console output and it will self-destruct in a day, but you can also store it if you wish.

Sample Online Cucumber Report

This feature can be enabled by either:

  • Adding Cucumber.properties file in src/test/resources/cucumber.properties and adding the below code:
cucumber.publish.enabled=true
  • Adding Junit Platform Properties file in src/test/resources/junit-platform.properties with the below code:
cucumber.publish.enabled=true
  • Add an environment variable:
CUCUMBER_PUBLISH_ENABLED=true
  •  From Junit Runner class:
@CucumberOptions(publish = true)

Conclusion

The new features in Cucumber 6 will be of great help to the business stakeholders who like to define their requirements more understandably. This will enable more scenarios to be added for various business needs and for you to perform more collaborative work towards delivering a stable product.

Cucumber Video Demo

References:

  1. Sample code for this Cucumber Demo on GitHub
  2. Cucumber-jvm on GitHub
  3. Cucumber installation docs (java)
  4. Cucumber report collections
  5. Zero Web Security

Are you ready?

Get started Schedule a demo