Cucumber options annotation

可紊 提交于 2019-11-30 13:44:23

问题


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.


回答1:


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.




回答2:


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.




回答3:


Hi as per my knowledge it all depends on the structure of you project. For example if you add the "Directory_a" ( directory which contains feature files) in the root level and StepDefinition, Hooks at src > test > java "Directory_b" And the TestRunner class at the same level ( src > test > java ) in "Directory_c"

Dir_a | src |---main |---test |------java |------Dir_b |------Dir_c

You saying "Dir_b" while you are in the "Dir_c" It will identify "Dir_b" or any directory in same level with out any additional paths so, It will be glue = {"Dir_b"}, But when you look at the directory that includes feature file you have to give the path from the root level In this case it's features = {"Dir_a"} or Giving the actual path eg :- "E://Project_Name//Dir_a" should work too

If your feature directory is NOT in root level make sure you give the path like "src/path to feature directory"

It will work fine :)



来源:https://stackoverflow.com/questions/17491989/cucumber-options-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!