Skip to content
Branch: master
Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src [TestNG] Remove gherkin from Cucumber TestNG API Aug 17, 2019
.gitignore [Core] Add property to select io.cucumber.core.backend.ObjectFactory … Jul 16, 2019
README.md [TestNG] Improve README.md Jul 21, 2019
pom.xml [All] Set version to 5.0.0-SNAPSHOT Jul 31, 2019

README.md

Cucumber TestNG

Use TestNG to execute cucumber scenarios. To use add the cucumber-testng dependency to your pom.

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

Create an empty class that extends the AbstractTestNGCucumberTests.

package io.cucumber.runtime.testng;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;

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

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.

Test composition

It is possible to use TestNG without inheriting from AbstractTestNGCucumberTests by using the TestNGCucumberRunner. See the RunCukesByCompositionTest Example for usage.

SkipException

Cucumber provides limited support for SkipException.

  • Throwing a SkipException results in both Cucumber and TestNG marking the test as skipped.
  • Throwing a subclass of SkipException results in Cucumber marking the test as failed and TestNG marking the test as skipped.

Parallel execution

Cucumber TestNG supports parallel execution of scenarios. Override the scenarios method to enable parallel execution.

public class RunCucumberTest extends AbstractTestNGCucumberTests {

    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }
}

Maven Surefire plugin configuation for parallel execution

<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
         <properties>
            <property>
               <name>dataproviderthreadcount</name>
               <value>${threadcount}</value>
            </property>
         </properties>
      </configuration>
   </plugin>
</plugins>

Where dataproviderthreadcount is the default number of threads to use for data providers when running tests in parallel.

You can’t perform that action at this time.