Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber options annotation

The cucumber-jvm javadocs states that purpose of the glue element is to specify the location of the stepdefinitions and hooks. However, this doesn't seem to work for me. Lets say I have my features in directory a, and my step definitions in directory b. Then,

@Cucumber.Options(
        features= "directory_a", 
            glue="directory_b"
)

will load my feature files from directory_a, but, it doesn't load my step definitions from directly_b. However, if I use

@Cucumber.Options(
        features= {"directory_a", "directory_b"}
)

then my features from directory_a is loaded, and my step definitions from directory_b are also picked up. Which is exactly what I want, however, I don't understand why the former isn't working? I'm guessing it has something to do with it expecting the URI to be formatted differently (maybe i need to prepend a classpath:// or something like that), but I can't find any information on this in the documentation.

like image 221
JustDanyul Avatar asked Jul 05 '13 15:07

JustDanyul


People also ask

What is @RunWith annotation in Cucumber?

The RunWith annotation commands to run the specified class instead of the created JUnit class. The CucumberOptions annotation specifies different options for the Cucumber test. In our case, we specify the following options: format – specifies the output format for the test result.

What is options in Cucumber?

What is Cucumber Options? In layman language, @CucumberOptions are like property files or settings for your test. Basically @CucumberOptions enables us to do all the things that we could have done if we have used cucumber command line.

What are annotations in Cucumber?

Annotation is a predefined text, which holds a specific meaning. It lets the compiler/interpreter know, what should be done upon execution. Cucumber has got the following few annotations − Given − It describes the pre-requisite for the test to be executed.

What is option tag in Cucumber?

In Cucumber, tags are used to associate a test like smoke, regression etc. with a particular scenario.


2 Answers

I have successfully used something like:

@RunWith(Cucumber.class)
@Cucumber.Options(
    //this code will only look into "features/" folder for features
    features={"classpath:features/"},
    glue = { "com.mycompany.cucumber.stepdefinitions", "com.mycompany.cucumber.hooks" },
    format = { "com.mycompany.cucumber.formatter.RuntimeInfoCatcher", "json:target/cucumber.json" },
    tags = { "@working" }
    )
public class CucumberStarterIT {
}

Looking at the doc at http://cukes.info/api/cucumber/jvm/javadoc/cucumber/api/junit/Cucumber.Options.html it specifies the options to be of type String[] so perhaps it's not expected to work "well" if you don't give it a single-value list. Try glue={"directory_b"} and see what happens for you.

like image 159
Dmitry Sharkov Avatar answered Sep 20 '22 18:09

Dmitry Sharkov


I had this problem too... and so far it seems to be that:

"features" is looking for a filesystem path:

features = "src/foo/bar"

whereas "glue" is looking for a package name:

glue = "foo.bar"

Not sure why they are different, but this seems to be working for me.

like image 23
Scott Bain Avatar answered Sep 22 '22 18:09

Scott Bain