Running cucumber-jvm tests using gradle


(Rakesh Patel) #1

Hi All,

very new to Gradle and even newer to Cucumber-jvm so please be patient.

I have created a Java project but have chosen Gradle as my build system.

I have copied over the cucumber-jvm examples (for Java) into my project and added the necessary dependencies to build.gradle.

When I run the cucumber test using my IDE (IntelliJ) it works ok. However, when running ‘gradle test’ on the command line, nothing happens as if it does not recognise the test.

Here’s the test that needs to run (and provides hooks into the cucumber architecture):

import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
import org.junit.runner.RunWith;
  @RunWith(Cucumber.class)
@Feature(value = "CarMaintenance.feature")
public class FuelCarTest {
}

Any ideas?


(René Groeschke) #2

Hi patel, I am not familiar with cucumber, but can you provide a small sample project (including build.gradle + sources) that demonstrates this issue and I’ll have a look at it.

regards, René


(Rakesh Patel) #3

how?


(Rakesh Patel) #4

actually, I think the problem may be because gradle does not include some resources - they end in .feature. How do I tell Gradle to include them into the build/classes directory?


(René Groeschke) #5

you have different options. you can: - paste the build.gradle file and a sample test here in the forum if it is a simple/short one - send it as an attachment to the gradle user mailing list (user@gradle.codehaus.org) - create an issue at http://issues.gradle.org and attache it there. - push a sample to github / etc.

regards, René


(René Groeschke) #6

as a default, the build classes directory contains compiled classes only. Resources are copied by the processResources task to build/resources/main. These two folders are added to the test classpath when running tests with gradle. Is this .feature file part of your main- or of your test resources? Does the .feature file appear in your build/resources/main (build/resources/test) folder?

regards, René


(Peter Niederwieser) #7

Please don’t double post here and on Stack Overflow.


(Rakesh Patel) #8

apologies for the double post but I assumed different communities so was hoping to cover all bases!!!

Anyway, I have created a sample project in GitHub now:

https://github.com/FinalFive/cucumber-jvm-java-example

Cucumber works by using the RunCukesTest class as a hook into the framework. Its meant to have no methods.

Now when I run tests with Intellij, it seems to work. Intellij merges the class files and resources inot the same directories (keeping prod and test separate).

However, Gradle keeps resources in a separate high-level directory all together. This may be part of the problem but I’m not sure.

In answer to Rene’s question, the feature files are part of the test/resources.


(Peter Niederwieser) #9

However, Gradle keeps resources in a separate high-level directory all together. This may be part of the problem but I’m not sure.

Does this solve the problem?

sourceSets.test.output.resourcesDir = sourceSets.test.output.classesDir

(Rakesh Patel) #10

that certainly provide the behaviour I am looking for! Thanks.

The tests are still not working so I think I need to debug cucumber next.

Do you think Gradle may be interfering with the @RunWith annotation at all?


(Peter Niederwieser) #11

@RunWith works fine with Gradle (we constantly use it ourselves); I’m not aware of any problems.