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 . If you don't have a folder for test resources, you need to create one.
Create the features folder
Right-click Test Resources Root and select .
Name the new folder
features
.
Create a new feature file
In the Project tool window, right-click the features folder and select
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 .
After that, you can add the code for the feature file and create your test scenario.
For more information about using 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 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.
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.
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:
Place the caret at
Scenario Outline
and press Alt+Enter.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.
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:
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.