Dependencies
Make sure the Cucumber version is the same for all Cucumber dependencies.
Watch the Cucumber School video lesson on installing Cucumber for JVM languages here.
Cucumber-JVM is published in the central Maven repository. You can install it by adding dependencies to your project.
If you are going to use the lambda expressions API (Java 8) to write the step
definitions, add the following dependency to your pom.xml
:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>6.10.4</version>
<scope>test</scope>
</dependency>
Otherwise, to write them using annotated methods, add the following dependency to your pom.xml
:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.10.4</version>
<scope>test</scope>
</dependency>
You can now run Cucumber from the command line or run Cucumber with Maven.
If you are using Gradle 4.10.3 or older, and you are going to use the lambda expressions API (Java 8) to write the step
definitions, add the following dependencies to build.gradle
:
dependencies {
testCompile 'io.cucumber:cucumber-java8:6.10.4'
testCompile 'io.cucumber:cucumber-junit:6.10.4'
}
repositories {
mavenCentral()
}
If you would prefer to write step definitions using annotated methods and you are using Gradle 4.10.3 or older, add the following dependencies to build.gradle
:
dependencies {
testCompile 'io.cucumber:cucumber-java:6.10.4'
testCompile 'io.cucumber:cucumber-junit:6.10.4'
}
repositories {
mavenCentral()
}
Similarly, if you want to use Gradle 5.0 or more recent, and would like to use the lambda API, add the following block to build.gradle
.
dependencies {
testImplementation 'io.cucumber:cucumber-java8:6.10.4'
testImplementation 'io.cucumber:cucumber-junit:6.10.4'
}
repositories {
mavenCentral()
}
Otherwise, to write them using annotated methods, add the following dependencies to build.gradle
:
dependencies {
testImplementation 'io.cucumber:cucumber-java:6.10.4'
testImplementation 'io.cucumber:cucumber-junit:6.10.4'
}
repositories {
mavenCentral()
}
You can now run Cucumber from the command line to execute by adding a cucumber task to build.gradle
.
It is also possible to use cucumber-junit to run your Cucumber test suite.
Cucumber does not come with an assertion library. Instead, use the assertion methods from a unit testing tool.
While it’s not required, we strongly recommend you include one of the dependency injection modules as well. This allows you to share state between step definitions without resorting to static variables (a common source of flickering scenarios).
You can help us improve this documentation. Edit this page.