IntelliJ IDEA 2021.2 Help

Create feature files

In Cucumber, feature files store high-level description of scenarios and steps in the Gherkin language. Gherkin uses plain English by default and promotes behavior-driven development.

Feature files are usually located in the features folder under Test Resources Root Test Resources Root icon. If you don't have a folder for test resources, you need to create one.

Create the features folder

  1. Right-click Test Resources Root icon Test Resources Root and select New | Directory.

  2. Name the new folder features.

Create a new feature file

  1. In the Project tool window, right click the features folder and select New | File.

  2. Name the new file. You can give it any name, but make sure to use the .feature extension (for example, BeerCans.feature).

    In the Project tool window, the new file will be marked with Gherkin org jetbrains plugins cucumber icons cucumber.

  3. After that, you can add the code for the feature file and create your test scenario.

For more information on how to use Gherkin, refer to Gherkin Syntax.

As you type, the IDE offers code completion and instant inspections with quick-fixes that help you define the scenario correctly. For example, creating a scenario goes before before adding step definitions, that is why at this stage the steps are highlighted as unresolved. When the feature file is finished, you can create step definitions with one shortcut.

Defining a scenario
Feature: Beer cans Scenario: Counting beer cans Given I have <opening balance> beer cans And I have drunk <processed> beer cans When I go to my fridge Then I should have <in stock> beer cans

In steps, you can use text notes enclosed in triple quotes. In this case, IntelliJ IDEA treats the text inside as a string and displays it when running the step.

Using text notes within a scenario
Feature: Beer cans Scenario: Counting beer cans Given I have <opening balance> beer cans """ Lorem ipsum dolor sit amet """
Using text notes: output shown in the Run tool window

Use the Examples table in Scenario Outline

The Scenario Outline component can be used to run the same Scenario for multiple sets of data. This data is defined in a table with the Examples header located underneath the scenario.

Use the Examples table if you want to test the entire scenario with multiple test data. If you need to pass a list of values to a single step definition, use Data tables.

To quickly create a table with examples:

  1. Place the caret at Scenario Outline and press Alt+Enter.

  2. From the list that opens, select Create Examples Section.

    IntelliJ IDEA creates a table in the correct format and adds there the information from the scenario. After that, you can fill in the table with the necessary data.

    Creating the Examples section using context actions
    Feature: Beer cans Scenario Outline: Counting beer cans Given I have <opening balance> beer cans And I have drunk <processed> beer cans When I go to my fridge Then I should have <in stock> beer cans Examples: | opening balance | processed | in stock | | 123 | 50 | 73 | | 1 | 1 | 0 |

You can find more information on how to use the Examples element in Using variables and examples.

Use another language for steps

Apart from the English language, you can describe steps in feature files in other spoken languages and dialects. To use your custom language, add # language: ... to the first line of the feature file. For example, to use German, type # language: de.

In this example, we use Australian English to describe steps:

Feature file in Australian English
# language: en-au Pretty much: Beer cans Reckon it's like: Counting beer cans Y'know I have <opening balance> beer cans Too right I have drunk <processed> beer cans It's just unbelievable I go to my fridge But at the end of the day I reckon I should have <in stock> beer cans You'll wanna: | opening balance | processed | in stock | | 123 | 50 | 73 | | 1 | 1 | 1 |

IntelliJ IDEA provides code completion, inspections, intention actions, and other coding assistance features in all supported spoken languages. For the full list of languages, refer to Spoken Languages in the Cucumber documentation.

Last modified: 27 August 2021