Sakamoto Kazuma
Sakamoto Kazuma

Reputation: 2579

Running Single cucumber-jvm .feature file from Gradle

I am integrating a cucumber-java with an existing gradle java project, that has a focus on test automation. There is no production code within this project, so making the entire project makes little sense.

What I would like to do is to create gradle tasks or a single gradle task with a -D property that specifies a cucumber .feature file to run cucumber-jvm on. All of the examples that I've seen show how to get cucumber-jvm to run as part of the build process. Instead, I would like to define a task testCucumber(type: Test) to run a single .feature file. How would I go about doing this?

Upvotes: 2

Views: 2645

Answers (1)

Sakamoto Kazuma
Sakamoto Kazuma

Reputation: 2579

I was able to get this to work by using a javaexec task in gradle.

 javaexec {
        main = "cucumber.api.cli.Main"
        classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
        args = ['--plugin', 'junit:target/cucumber-junit-report.xml', '--plugin', 'pretty', '--glue', 'StepDefinitions', 'src/test/Features/FeatureFilename.feature']
    }

This is assuming that all step definitions are defined within a package called "StepDefinitions".

Upvotes: 1

Related Questions