黄瓜jvm varargs支持步骤定义

Mru*_*sar 4 java bdd cucumber-jvm cucumber-junit

如何在黄瓜java绑定中定义步骤定义时使用varargs的强大功能.我有下面的步骤

Given I have following product: prod1, prod2, prod3
Run Code Online (Sandbox Code Playgroud)

我的步骤定义

@Given("^I have following product [(exhaustive list of products or pattern of the product names)]$")
public void stepDef(String...args)
{
//Process varargs array "args" in here
}
Run Code Online (Sandbox Code Playgroud)

我知道解决方法可以是除了冒号后的完整字符串,然后在代码中使用split(",")拆分字符串并将其转储到数组中.但我只是想知道黄瓜本身是否支持varargs模式.

TIA!

Dud*_*ude 11

我不知道黄瓜是否支持varargs,但也许你可以通过直接列表匹配来达到你的目标?

您可以在Cucumber的Feature文件中定义示例列表

您可以在步骤结束时定义它们:

@Given i want a list
|Entry1|
|Entry2|
Run Code Online (Sandbox Code Playgroud)

或者内联:

@Given i want a list: Entry1, Entry2
Run Code Online (Sandbox Code Playgroud)

然后你可以有胶水代码,如:

@Given(^i want a list$)
public void i_want_a_list(List<String> entries) {
//do stuff
}   

@Given(^i want a list: (.*)$)
public void i_want_a_list(List<String> entries){
 //Do something with the list
}
Run Code Online (Sandbox Code Playgroud)

你可以在这里找到更多信息:https://cukes.info/docs/reference/jvm#step-definitions