Cucumber
Cucumber is a testing framework that supports behavior-driven development and allows you to write features and scenarios in a human-readable language.

Cucumber support in IntelliJ IDEA includes the following features:
- Syntax and error highlighting
- Code completion
- A dedicated quick-fix to create step definitions
- Navigation between step definitions and steps
- Support for other spoken languages in feature files
Cucumber for other languages
IntelliJ IDEA allows you to work with Cucumber in other languages apart from Java provided that the required plugins are installed and enabled.
Also, make sure that your edition of IntelliJ IDEA supports the language you are interested in. Languages available only in IntelliJ IDEA Ultimate are marked with the Ultimate badge. For more information about IntelliJ IDEA editions, refer to comparison matrix.
Cucumber for Groovy
To use Cucumber with Groovy, the following plugins must be installed and enabled:
- Gherkin
- Cucumber for Java
- Cucumber for Groovy
Cucumber for Kotlin
To use Cucumber with Kotlin, the following plugins must be installed and enabled:
- Gherkin
- Cucumber for Kotlin
Cucumber for Scala
To use Cucumber with Scala, the following plugins must be installed and enabled:
- Scala
- Gherkin
- Cucumber for Scala
Cucumber for Ruby
To use Cucumber with Ruby, the following plugins and gems must be installed and enabled:
- The Ruby plugin
- The Gherkin plugin
- cucumber gem (for Ruby projects), or cucumber and cucumber-rails (for Rails applications); refer to Bundler
For more information, refer to Cucumber for Ruby.
Cucumber for JavaScript
To use Cucumber with JavaScript, the following plugins and gems must be installed and enabled:
- JavaScript and TypeScript
- Node.js
- Cucumber.js
- Gherkin
For more information, refer to Cucumber for JavaScript.
Cucumber.js
Cucumber.js versions 6.0.0+ are supported in IntelliJ IDEA 2020.3.1 and later.
Cucumber.js is a test framework for behavior-driven JavaScript development. Cucumber.js tests are written in the human-readable Gherkin language and are stored in feature files that have the feature extension. IntelliJ IDEA integrates with Cucumber.js and recognizes features written in Gherkin, so you can run Cucumber.js test right from the IDE.
Before you start
- To work with Cucumber.js versions 6.0.0+, make sure you are using IntelliJ IDEA 2020.3.1 or later.
- Download and install Node.js.
- Make sure the JavaScript and TypeScript and Gherkin required plugins are enabled on the Settings | Plugins page, tab Installed . For more information, refer to Managing plugins.
- Install and enable the Cucumber.js plugin on the Settings | Plugins page, tab Marketplace , as described in Installing plugins from JetBrains Marketplace.
Install Cucumber.js
- In the embedded Terminal ( Alt+F12 ) , type one of the following commands:
- npm install cucumber for local installation in your project.
- npm install -g cucumber for global installation.
- npm install —save-dev cucumber to install Cucumber.js as a development dependency.
Create test definitions
With IntelliJ IDEA, you can write step definitions both in JavaScript and in TypeScript. IntelliJ IDEA detects and highlights the steps where definitions are missing and suggests a quick-fix to generate them.
- Place the caret at the step without a definition, press Alt+Enter , and select Create step definition or Create all step definitions .
Alternatively, hover over the step and use the links in the popup. 
- In the dialog that opens, specify the name for the new file and the language to write the definitions in.
If such file already exists, IntelliJ IDEA displays a popup where you have to select a file to add the definition to or choose to create a new file.
Run tests
Cucumber.js tests are launched only through a run/debug configuration.
Create a Cucumber.js run configuration
- Open the Run/Debug Configuration dialog ( Run | Edit Configurations in the main menu), click in the left-hand pane, and select Cucumber.js from the list. The Run/Debug Configuration: Cucumber.js dialog opens. To create a run/debug configuration for all the tests in a single test file, select Run from its context menu. To create a run/debug configuration for one scenario, select Create Scenario: from its context menu in the editor.
- In the Feature file or directory field, specify the tests to run. Type the path to a specific .feature file or to a folder, if you want to run a bunch of features.
- Specify the Node.js interpreter to use. If you choose the Project alias, IntelliJ IDEA will automatically use the project default interpreter from the Node interpreter field on the Node.js page . In most cases, IntelliJ IDEA detects the project default interpreter and fills in the field itself. You can also choose another configured local or remote interpreter or click and configure a new one.
- In the Cucumber package field, specify the path to the folder where the cucumber package is stored.
- Specify the working directory of the application. By default, the Working directory field shows the project root folder. To change this predefined setting, specify the path to the desired folder.
- Optionally:
- In the Name Filter field, type the name of a specific scenario to run instead of all the scenarios from the feature file or directory.
- Specify the command-line arguments to be passed to the executable file, such as -r —require LIBRARY|DIR , -t —tags TAG_EXPRESSION , or —coffee . For more information, refer to native built-in help available through the cucumber-js —help command.
- In the Environment variables field, specify the environment variables for your application.
If you create a run/debug configuration for one scenario ( Create Scenario: ), IntelliJ IDEA fills in the name of the scenario in the Name Filter field automatically.
Run tests via a run configuration
- Select the Cucumber.js run/debug configuration from the list of configurations and click in the list or on the toolbar.
- Monitor test execution and analyze test results in the Test Runner tab of the Run tool window. For more information, refer to Explore test results.
Run tests from a test file
- To run a single test, open the test file in the editor, place the caret at the scenario to run, and then select Run Scenario: from the context menu.
- To run all tests from a single test file, open the test file in the editor or select it in the Project tool window and choose Run from the context menu.
In either case, IntelliJ IDEA creates a run/debug configuration which you can save and use later.
Debug tests
- Set breakpoints where necessary.
Debug tests via a run configuration
- Select the Cucumber.js run/debug configuration from the list of configurations and click in the list or on the toolbar.
- Monitor test execution and analyze test results in the Test Runner tab of the Run tool window. For more information, refer to Explore test results.
Debug tests from a test file
- To debug a single test, set the breakpoints where necessary, place the caret at the scenario to debug, and then select Debug Scenario: from the context menu.
- To debug all tests from a single test file, open the test file in the editor or select it in the Project tool window and choose Debug from the context menu.
In either case, IntelliJ IDEA creates a run/debug configuration which you can save and use later.
Run and debug tests written in TypeScript

- Create a Cucumber.js run/debug configuration as described above.
- In the Before launch area, click, select Compile TypeScript from the list, and then specify the tsconfig.json file to use. IntelliJ IDEA will run the TypeScript compiler with this tsconfig.json before running Cucumber.js. Alternatively, set up TypeScript compilation as another build step.
- To debug tests written in TypeScript, open your tsconfig.json and set «sourceMap»: true to enable source maps.
Navigation
With IntelliJ IDEA, you can jump between a file and the related test file or from a test result in the Test Runner Tab to the test.
- To jump between a test and its subject or vice versa, open the file in the editor and select Go to | Test or Go to | Test Subject from the context menu, or just press Control+Shift+T .
- To jump from a step in a .feature file to the step definition, press and hold Control , hover over the step, and click the step when it turns into a link.
- To jump from a test result to the test definition, click the test name in the Test Runner tab twice, or select Jump to Source from the context menu, or just press F4 . The test file opens in the editor with the caret placed at the test definition.
Configure syntax highlighting
You can configure Cucumber.js-aware syntax highlighting according to your preferences and habits.
- In the Settings dialog ( Control+Alt+S ), go to Editor | Color Scheme | Cucumber .
- Select the color scheme, accept the highlighting settings inherited from the defaults or customize them as described in Colors and fonts.
Enable Cucumber support
To be able to use Cucumber in your application, make sure that the necessary plugins are enabled and add the Cucumber library to your project.
Enable plugins
In IntelliJ Ultimate , the required plugins are bundled and enabled by default. However, we recommend you to make sure that they are switched on.
In IntelliJ Community , the necessary plugins are not bundled, that is why you need to install and enable them.

- Press Control+Alt+S to open the IDE settings and then select Plugins .
- Switch to the Installed tab and make sure that the following plugins are enabled (the plugins must be enabled in the specified order):
- Gherkin
- Cucumber for Java
- Cucumber for Groovy (optional: install this plugin if you want to create step definitions in Groovy)
- If the plugins are not installed, switch to the Marketplace tab, type their names in the search field in the specified order, and click Install next to each of them.
- Apply the changes and close the dialog. Restart the IDE if prompted.
Add the Cucumber library
Follow these steps to add a library if you’re building your project with the native IntelliJ IDEA builder:

- In the main menu, go to File | Project Structure ( Control+Alt+Shift+S ).
- Under Project Settings , select Libraries and click | From Maven .
- In the dialog that opens, specify the artifact of the library version that you want to use in your project, for example: io.cucumber:cucumber-java:jar:6.1.1 or io.cucumber:cucumber-java8:jar:6.1.1 (if you want to use lambda expressions in step definitions). Click OK .
- Apply the changes and close the dialog.
Follow these steps if you’re using Maven in your project:
-
In your pom.xml , add the following dependencies (make sure to specify the latest version of Cucumber):
io.cucumber cucumber-java 6.1.1 test
Alternatively, if you want to use lambda expressions in step definitions, add:
io.cucumber cucumber-java8 6.1.1 test For more information about working with Maven, refer to Maven dependencies.
Use these steps if you’re building your project with Gradle.
-
Open your build.gradle and add the following dependencies (make sure to specify the latest version of Cucumber): For Gradle 5 and later, add:
dependencies < testImplementation 'io.cucumber:cucumber-java:6.1.1' >
Alternatively, if you want to use lambda expressions in step definitions, add:
dependencies < testImplementation 'io.cucumber:cucumber-java8:6.1.1' >
For Gradle 4.10.3 and earlier, add:
dependencies < testCompile 'io.cucumber:cucumber-java:6.1.1' >
Alternatively, if you want to use lambda expressions in step definitions, add:
dependencies < testCompile 'io.cucumber:cucumber-java8:6.1.1' >Apart from the Cucumber library, you might need to add a library for JUnit or another testing framework.
Prepare folder structure
Make sure that your project has the following folders:

- Test Sources Root: a folder that stores your test code
- Test Resources Root: a folder that stores files associated with your test sources
Как установить cucumber for java в idea

This tutorial will focus on the installation of Maven, Cucumber, JUnit and IntelliJ and other plugins to get you started writing your test suite in Java. This will not discuss theories and on how to write tests in Java.
How to install AdoptOpenJDK on MacOS
brew tap AdoptOpenJDK/openjdk
Install the specific version of OpenJDK
brew install --cask adoptopenjdk11
Check if you’ve successfully added OpenJDK in your Third-Party-Repositories
brew list --full-name
List all installed JDK.
/usr/libexec/java_home -V
Check the current version of your JDK
java -version
To support multiple version of JDK, copy the following line of commands in your .bash_profile . The alias java11 is a quick way to reference an export command to change the version assigned in JAVA_HOME environment variable.
export JAVA_11_HOME=$(/usr/libexec/java_home -v 11.0.11) export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8.0_242) alias java11="export JAVA_HOME=$JAVA_11_HOME" alias java8="export JAVA_HOME=$JAVA_8_HOME"
How to install IntelliJ and plugins for Maven, Cucumber, Gherkin and JUnit
Download and install IntelliJ. For this example, I have installed the Community version of IntelliJ. For more IntelliJ configurations and on how to install this on Windows, please read my tutorial about “ Install Amazon Corretto and IntelliJ IDEA in Windows“.
To add the plugins for Maven, Cucumber for Java and Gherkin go to IntelliJ IDEA > Preferences > Plugins. These plugins will allow you to generate your Maven project and start writing your Cucumber feature files.

If you can’t find the plugins in the list, you may also type the name in the search bar. Search for the name of the plugins.
- Cucumber for Java
- Gherkin
- Maven
- JUnit
Create your first Maven project. Go to File > New Project > Maven > Next. Then Give your Maven project a Name and click on Finish button.

Alternatively, you can add all your test framework dependencies in pom.xml file that will be added after you generate your fist Maven project.

In case pom.xml complain about dependency not found error, go to File > Invalidate Caches. This action will restart your IntelliJ.
Install Apache Maven (not the IntelliJ plugin). Using brew in MacOS
Maven is an important tool in Java for managing the build life cycle of your project. Their website provides a central repository for managing project JARS. It helps to maintain a common structure for your project. And provides commands that allow you to integrate CI tools like Jenkins for test automation.
The easy way to install Maven is by using brew.
brew install maven mvn -v
If you are having trouble with the installation using brew, you can also do a manual installation of Maven. Download the Maven JAR and follow the steps on how to add the bin directory to your PATH environment variable.
Run your test suite in Maven
org.apache.maven.plugins maven-surefire-plugin 3.0.0-M5 Integration testing useful Maven commands
Here are some of the useful commands in Maven for managing your project’s test suite.
Generate a new Maven project through CLI.
mvn archetype:generate -B -DgroupId=com.rex_maven.example -DartifactId=MyFirstMaven -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=0.1
You can find more options for defining system properties using the -D tag. The archetype is for defining the structure of your project and in this example we used the basic structure maven-archetype-quickstart.
Attempt to clean the files and directories generated by Maven during its build. Deletes the target folder.
mvn clean
Compile the source code of the project and checks for syntax errors. However, It does not actually run the test.
mvn compile
Run all tests using a suitable unit testing framework. Also, it will attempt to compile if it has not been compiled yet.
mvn test
Sometimes, you may need to just run a single test or you need to trigger your test suite through a test runner class. This is also possible by specifying this in a tag. For example, I have a JUnit test runner ApiTestRunner to trigger all my cucumber tests.
package org.example.runner; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features = «src/test/java/org/example/features», glue = «org.example.steps», tags = «@hello_world», stepNotifications = true, plugin = , monochrome = true ) public class ApiTestJunitRunner
Then I can trigger my test runner class in Maven.
mvn -Dtest=ApiTestRunner test
Maven compile error. Source option 6 is no longer supported. Use 7 or later
If you are using JDK version 11, apply the release version under configuration tag. Take note, in the older version you specify the source and target parameters. But in here you only need the release parameter.
org.apache.maven.plugins maven-compiler-plugin 3.8.1 11 In my next tutorial, I will be discussing on how to set up a Java Maven project for testing using Cucumber JUnit. I will have examples on how to run your tests directly in Cucumber feature files. And also, using JUnit test runner class.
Related posts:
- Java Maven project testing using Cucumber JUnit
- Install Amazon Corretto and IntelliJ IDEA in Windows
- Upgrade to OpenJDK Temurin using Homebrew
- Python unittest tips and tricks