This page describes tools commonly used with Java.
IDEs
IntelliJ IDEA
You can find more information on using Cucumber with IntelliJ IDEA in the IntelliJ IDEA Cucumber help pages
Eclipse
- Eclipse has the Cucumber Eclipse plugin
Build tools
The most widely used build tools for Java are Maven and Gradle.
Maven
To run Cucumber with Maven, make sure that:
- Maven is installed
- The environment variable
MAVEN_HOME
is correctly configured - The IDE is configured with the latest Maven installation
Steps:
- Create a new Maven project or fork cucumber-java examples on Github
Add the following dependency to the
pom.xml
<dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>6.10.4</version> </dependency>
Add feature
.feature
files and associated step mapping classes.java
insrc/test/resources
andsrc/test/java
folders respectively.Run the following Maven from the directory path where the
pom.xml
file is located:mvn clean install -Dcucumber.glue="package_name_of_step_definitions" \ -Dcucumber.plugin="pretty path\to\featurefiles"
Gradle
To run Cucumber with Gradle, make sure that:
- Gradle is installed
- The environment variable
GRADLE_HOME
is correctly configured - The IDE is configured with the latest Gradle installation
Steps:
- Create a new Gradle project or look at gradle-cucumber-runner example on Github
If you are going to use Gradle 4.10.3 or older, add this dependency block to
build.gradle
.dependencies { testCompile 'io.cucumber:cucumber-java:6.10.4' }
For Gradle 5.0 or more recent, you can add the following dependency block to
build.gradle
.dependencies { testImplementation 'io.cucumber:cucumber-java:6.10.4' }
For Gradle 4.10.3 or older, add the following configuration to
build.gradle
.configurations { cucumberRuntime { extendsFrom testRuntime } }
For Gradle 5.0 or more recent, the following configuration must be added to
build.gradle
.configurations { cucumberRuntime { extendsFrom testImplementation } }
Add feature
.feature
files and associated step mapping classes.java
insrc/test/resources
andsrc/test/java
respectively in agradle.cucumber
package.Add the following Gradle
cucumber
task inbuild.gradle
task cucumber() { dependsOn assemble, testClasses doLast { javaexec { main = "io.cucumber.core.cli.Main" classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources'] } } }
Run the following gradle task from the directory path where
build.gradle
file is located:gradle cucumber