How do I set the path to my Cucumber features using cucumber-junit?

The classpath option is not obvious in the Cucumber documentation (it is not in the JavaDoc either), I ended up inferring it from the CLI documentation (edit: link is dead, can't find an equivalent), which has other location options documented. See the List configuration options section in the docs. It is also not obvious how to get the feature defintions from another module of a multi module Maven projectg.

This is what got me going (running from IDE and command line) in a Maven multi module project.

@CucumberOptions(
        features = {"classpath:product"},
        //...
)
public class RunCukesTest extends AbstractTestNGSpringContextTests {

where my feature files were located in

main-project
    sub-module-1
        src/test/java/com/foo/
            RunCukesTest.java
        src/test/resources/product/
            feature_1.feature
            feature_2.feature
    sub-module-2
        ...

It pleases me not to see src/test/resources in the path. Note that there is no leading / in the path. Using the classpath is less brittle, because the classpath (rather than the current working directory) must be well defined.


You can use

@CucumberOptions(
    format = "pretty",
    tags = {"~@Ignore"},
    features = "src/test/resources/com/"  //refer to Feature file
)

for scan all of feature file in package


Take a look at my question here:

You can specify a location on the classpath by setting the feature attribute in the options annotation like

@Cucumber.Options(features="src/test/resources")

Edit:

in new versions code is

@CucumberOptions(features="src/test/resources")

Ok, I can only put this on monday morning... The directory layout I used wasn't correct, I forgot to put the cucumber features into subdirectories matching my package structure.

Make sure you create the needed package directories also in src/test/resources/!