Cucumber-jvm

Cucumber-jvm is published in the central Maven repository. You can install it by adding dependencies to your project.

Dependencies

Make sure the Cucumber version is the same for all Cucumber dependencies.

Maven

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>4.2.0</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>4.2.0</version>
    <scope>test</scope>
</dependency>

You can now run Cucumber from the command line or run Cucumber with Maven.

Gradle

If 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:4.2.0'
    testCompile 'io.cucumber:cucumber-junit:4.2.0'
}

repositories {
    mavenCentral()
}

Otherwise, to write them using annotated methods, add the following dependencies to build.gradle:

dependencies {
    testCompile 'io.cucumber:cucumber-java:4.2.0'
    testCompile 'io.cucumber:cucumber-junit:4.2.0'
}

repositories {
    mavenCentral()
}

You can now run Cucumber from the command line to execute by adding a cucumber task to build.gradle.

Snapshot releases

To take advantage of functionality that has been committed to the git master branch, but hasn’t been released to the central Maven repo yet, you can use SNAPSHOT builds from the sonatype snapshot repo.

If you are using Maven, add the sonatype repository to your pom.xml:

<repository>
    <id>sonatype-snapshots</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

Then, add a dependency to the snapshot version to your pom.xml:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.2.0-SNAPSHOT</version>
    <scope>test</scope>
</dependency>

You can find the current snapshot version number here.

If you are using Gradle, check the build.gradle file in the cucumber-java-skeleton project.

Assertions

Cucumber does not come with an assertion library. Instead, use the assertion methods from a unit testing tool.

Dependency Injection

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.