Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src [All] Clean up unessesary types and unused code Aug 22, 2019
README.md [All] Use JUnit 5 internally Aug 18, 2019
pom.xml [All] Use JUnit 5 internally Aug 18, 2019

README.md

Cucumber JUnit

Use JUnit to execute cucumber scenarios. To use add the cucumber-junit dependency to your pom.xml:

<dependencies>
  [...]
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
  [...]
</dependencies>

Create an empty class that uses the Cucumber JUnit runner.

package com.example;

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "json:target/cucumber-report.json")
public class RunCucumberTest {
}

This will execute all scenarios in same package as the runner, by default glue code is also assumed to be in the same package. The @CucumberOptions can be used to provide additional configuration to the runner.

Using JUnit Rules

Cucumber supports JUnits @ClassRule, @BeforeClass and @AfterClass annotations. These will executed before and after all scenarios. Using these is not recommended as it limits the portability between different runners; they may not execute correctly when using the commandline, IntelliJ IDEA or Cucumber-Eclipse. Instead it is recommended to use Cucumbers Before and After hooks.

Using other JUnit features

The Cucumber runner acts like a suite of a JUnit tests. As such other JUnit features such as Custom JUnit Listeners and Reporters can all be expected to work.

For more information on JUnit, see the JUnit web site.

Assume

Through Assume and Assumptions JUnit4 and JUnit5 provide:

a collection of utility methods that support conditional test execution based on assumptions.

In direct contrast to failed assertions, failed assumptions do not result in a test failure; rather, a failed assumption results in a test being aborted.

Assumptions are typically used whenever it does not make sense to continue execution of a given test method — for example, if the test depends on something that does not exist in the current runtime environment.

The Cucumber runner supports Assume and will marked skipped scenarios as skipped.

Parallel Execution with Maven

Cucumber JUnit supports parallel execution of feature files across multiple threads. To enable this with maven set the parallel property to either methods or both.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <!-- Use 2.22.1 or higher -->
            <version>${maven-surefire-plugin.version}</version>  
            <configuration>
                <parallel>both</parallel>
                <threadCount>4</threadCount>
            </configuration>
        </plugin>
    </plugins>
</build>
You can’t perform that action at this time.