Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 步骤定义中的jvm varargs支持_Java_Bdd_Cucumber Jvm_Cucumber Junit - Fatal编程技术网

Java 步骤定义中的jvm varargs支持

Java 步骤定义中的jvm varargs支持,java,bdd,cucumber-jvm,cucumber-junit,Java,Bdd,Cucumber Jvm,Cucumber Junit,如何在java绑定中定义步骤定义时使用varargs的强大功能。我有以下步骤 Given I have following product: prod1, prod2, prod3 我的步骤定义 @Given("^I have following product [(exhaustive list of products or pattern of the product names)]$") public void stepDef(String...args) { //Process var

如何在java绑定中定义步骤定义时使用varargs的强大功能。我有以下步骤

Given I have following product: prod1, prod2, prod3
我的步骤定义

@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
}
我知道解决方法可以是除去冒号后面的完整字符串,然后在代码中使用split(“,”)打断字符串并将其转储到数组中。但我只是想知道cucumber本身是否支持varargs模式


TIA

我不知道cucumber中是否支持varargs,但也许您可以通过直接列表匹配来实现您的目标

可以在Cucumber中的要素文件中定义示例列表

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

@Given i want a list
|Entry1|
|Entry2|
或内联:

@Given i want a list: Entry1, Entry2
然后您可以使用如下粘合代码:

@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
}
@给定(^i需要一个列表$)
公共无效我想要一个列表(列表条目){
//做事
}   
@给定(^i需要一个列表:(.*))
公共无效我想要一个列表(列表条目){
//对清单做点什么
}
您可以在此处找到更多信息:

如果您的步骤如下所示-
鉴于我有以下产品
|产品1|
|产品2|
|prod3|
然后步骤定义变为-
@给定(“^I有以下产品$”)
public void i_have_following_产品(DataTable dt)引发异常
{
List outerList=dt.rows();
对于(列表内部列表:外部列表)
{
System.out.println(innerlist.get(0));
}
}

thnx..但我想知道是否支持varags..我已经研究了其他替代方案这似乎目前还不可能,但我不知道varargs在哪方面比集合更强大?
If your steps like below-
Given I have following product
|prod1|
|prod2|
|prod3|
Then step definition becomes-

@Given("^I have following product$")
public void i_have_following_product(DataTable dt) throws Exception
{
  List<List<String>> outerList = dt.rows();
  for(List<String> innerList : outerList)
    {
      System.out.println(innerLlist.get(0));
    }
}