selina
selina

Reputation: 47

How do i invoke cucumber test project with gradle?

I am very new to gradle and i am so confused in how to invoke my project so i can run my Cucumber test. What do i do after creating a build.gradle file? my build.gradle looks like this apply plugin: 'java'

dependencies {
    testCompile 'info.cukes:cucumber-java:1.2.4'
    testCompile 'info.cukes:cucumber-junit:1.2.4'
    testCompile 'junit:junit:4.12'
}

repositories {
    mavenCentral()
}

project.ext {
    cucumberVersion = '1.2.4'
    junitVersion = '4.11'
}
test {
    testLogging.showStandardStreams = true
    systemProperties System.getProperties()
}

Upvotes: 2

Views: 6774

Answers (4)

Karthikeyan
Karthikeyan

Reputation: 125

Added the below in build.gradle file

test {
    testLogging.showStandardStreams = true
    systemProperties System.getProperties()
}

It invoked my cucumber test for gradle clean build

Upvotes: 1

Mujibur Rahman
Mujibur Rahman

Reputation: 461

Use Gradle Cucumber JVM Plugin. It works perfectly and has pretty html reports integrated.

https://github.com/commercehub-oss/gradle-cucumber-jvm-plugin

Upvotes: -1

Oleksandr Romanov
Oleksandr Romanov

Reputation: 21

Just to extend Thomas's great answer I want to mention, that if your have your custom TestRunner class for specific suite of tests (like previously mentioned RunCukesTest or e.g. RegressionTestRunner), it is possible to add custom task for running the exact runner:

task runRegressionTests(type: Test) << {
include "RegressionTestRunner.class"
 }

And then it is easy to run regression tests by gradle task:

gradle runRegressionTests

If you have a multiple runner classes for different suites (RegressionTestRunner, SanityTestRunner, etc) - it is useful to write a custom pattern for testing task which will recognize and run defined runner class.

E.g.:

runRegressionTests, runSanityTests.

Upvotes: 1

Thomas Sundberg
Thomas Sundberg

Reputation: 4343

You create a JUnit class that uses a Cucumber runner to execute Cucumber.

@RunWith(Cucumber.class)
public class RunCukesTest {
}

in your test directory.

I describe it with more details here: http://www.thinkcode.se/blog/2015/01/30/bdd-with-cucumberjvm-at-geecon-tdd-2015

Another option is to start with the Java skeleton project that is available here: https://github.com/cucumber/cucumber-java-skeleton

And then follow the steps outlined in http://www.thinkcode.se/blog/2015/12/26/gradle-and-cucumberjvm

Upvotes: 1

Related Questions