How to run the cucumber test using gradle

user3350712 picture user3350712 · Feb 7, 2015 · Viewed 38.6k times · Source

I'm having trouble running Cucumber tests in Gradle. I am using cucumber-jvm.

Class TestNGCucumberRunner extends the AbstractTestNGCucumberTests and testng annotations with @beforesuite, @aftersuite..

I usually run the TestNGCucumberRunner.java in IntelliJ by right-click and it runs successfully. Now I want to

  1. Invoke the TestNGCucumberRunner.java in gradle

or

  1. Invoke all the features in gradle

I tried to execute the TestNGCucumberRunner.java as a javaexec but that fails.

I tried to execute all the feature files in the package. I have used apply plugin: 'com.github.samueltbrown.cucumber' also.

Answer

Carlo Bellettini picture Carlo Bellettini · Oct 2, 2015

UPDATE:

My new setup uses a different plugin that supports parallel execution of scenarios, better reporting, and is still actively maintained:

build.gradle

plugins {
  ...
  id "com.commercehub.cucumber-jvm" version "0.11"
}

addCucumberSuite 'cucumberTest'

dependencies {
  ...
  cucumberTestCompile 'info.cukes:cucumber-java:1.2.5'  // or -java8 if you prefer lambda notation

}

directory structure:

└── src
    ├── cucumberTest
    │   ├── java
    │   │   └── package1 
    │           └──       <- Glue
    │   └── resources    
    │       └── package2 
    │           └──       <- Features
    ├── main
    │   └── java
    └── test
        └── java

package1 and package2 names (together with many other options) can be specified in the build.gradle file


OLD

My previous setup for using cucumber for java with gradle.

build.gradle

plugins {
    id "java"
    id "com.github.samueltbrown.cucumber" version "0.9"
  }   

dependencies {
    cucumberCompile 'info.cukes:cucumber-java:1.2.4'
}

cucumber {
    formats = ['pretty','junit:build/cucumber.xml']
}

Directory layout

└── src
    ├── cucumber
    │   ├── java         <- Glue
    │   └── resources    <- Features
    └── main
    │    └── java
    └── test
        └── java

Command

gradle cucumber