黄瓜选项注释

Jus*_*yul 18 cucumber cucumber-jvm

cucumber-jvm javadocs指出glue元素的目的是指定stepdefinitions和hooks的位置.但是,这对我来说似乎不起作用.假设我在目录a中有我的功能,在目录b中有我的步骤定义.然后,

@Cucumber.Options(
        features= "directory_a", 
            glue="directory_b"
)
Run Code Online (Sandbox Code Playgroud)

将从directory_a加载我的功能文件,但是,它不会从direct_b加载我的步骤定义.但是,如果我使用

@Cucumber.Options(
        features= {"directory_a", "directory_b"}
)
Run Code Online (Sandbox Code Playgroud)

然后加载来自directory_a的我的功能,并且还会拾取来自directory_b的步骤定义.这正是我想要的,但是,我不明白为什么前者不起作用?我猜它与它有关,期望URI的格式不同(也许我需要在类路径前面添加//或类似的东西),但我在文档中找不到任何关于此的信息.

Dmi*_*kov 17

我成功地使用了类似的东西:

@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 {
}
Run Code Online (Sandbox Code Playgroud)

查看http://cukes.info/api/cucumber/jvm/javadoc/cucumber/api/junit/Cucumber.Options.html上的文档,它指定了类型的选项,String[]因此可能不会"很好"地工作如果你不给它一个单值列表.试着glue={"directory_b"}看看会发生什么.

  • 从上面的示例或文档中尚不清楚,但胶水仅采用包名称。 (2认同)

小智 6

我也有这个问题......到目前为止,它似乎是这样的:

"features"正在寻找文件系统路径:

features = "src/foo/bar"
Run Code Online (Sandbox Code Playgroud)

而"胶水"正在寻找包名:

glue = "foo.bar"
Run Code Online (Sandbox Code Playgroud)

不知道为什么他们不同,但这似乎对我有用.