Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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 如何将任意数量的条件与一个“匹配”;然后";插手?_Java_Cucumber_Cucumber Jvm_Cucumber Junit_Cucumber Java - Fatal编程技术网

Java 如何将任意数量的条件与一个“匹配”;然后";插手?

Java 如何将任意数量的条件与一个“匹配”;然后";插手?,java,cucumber,cucumber-jvm,cucumber-junit,cucumber-java,Java,Cucumber,Cucumber Jvm,Cucumber Junit,Cucumber Java,在cucumber(java版本)中,如何用一个“then”函数匹配所有步骤 例如,我希望能够在一个函数中匹配以下所有函数: Then the response status will be "200" Then the response status will be "200" or "302" Then the response status will be "200" or "302" or "404" 我需要为每个“或”写一个匹配器吗 有没有一种方法可以为上述所有情况编写一个匹配器 例

在cucumber(java版本)中,如何用一个“then”函数匹配所有步骤

例如,我希望能够在一个函数中匹配以下所有函数:

Then the response status will be "200"
Then the response status will be "200" or "302"
Then the response status will be "200" or "302" or "404"
我需要为每个“或”写一个匹配器吗

有没有一种方法可以为上述所有情况编写一个匹配器

例如,如何将这些功能组合成一个函数

@Then("^the response status should be \"([^\"]*)\"$")
public void the_response_status_should_be(String arg1) throws Throwable {
    System.out.println("** the response status should be "+arg1);
}

@Then("^the response status should be \"([^\"]*)\" or \"([^\"]*)\"$")
public void the_response_status_should_be_or(String arg1, String arg2) throws Throwable {
    System.out.println("** the response status should be "+arg1+" "+arg2);
}

@Then("^the response status should be \"([^\"]*)\" or \"([^\"]*)\" or \"([^\"]*)\"$")
public void the_response_status_should_be_or(String arg1, String arg2, String arg3) throws Throwable {
    System.out.println("** the response status should be "+arg1+" "+arg2+" "+arg3);
}
这可能吗


谢谢

假设值列表可以映射到具有包含

...
Then the response status will be one of the following
    | response status | 
    | 200             |
    | 302             |
    | 404             |
....
用黄瓜代码

@Then(^the response status will be one of the following$)
public void doResponseStuff(List<String> responses){
   // use response codes...
}    
@然后(^响应状态将是以下$之一)
公共无效或响应(列出响应){
//使用响应代码。。。
}    

假设值列表可以映射到具有包含

...
Then the response status will be one of the following
    | response status | 
    | 200             |
    | 302             |
    | 404             |
....
用黄瓜代码

@Then(^the response status will be one of the following$)
public void doResponseStuff(List<String> responses){
   // use response codes...
}    
@然后(^响应状态将是以下$之一)
公共无效或响应(列出响应){
//使用响应代码。。。
}    

除了@Reimeus好答案之外,您还可以在步骤定义中匹配
列表

特征定义:

...
Then the response status will be 200,302,404
...
Java步骤代码:

@When("^the response status will be (.*)$")
public void the_response_status_should_be(List<Integer> statusList) throws Throwable {
   //...
}
@何时(“^response status将为(.*)$”)
public void \u响应\u状态\u应为(列表状态列表)可丢弃{
//...
}

我认为这两种选择都符合你的要求。希望它有助于

替代@Reimeus好答案,您还可以在步骤定义中匹配
列表

特征定义:

...
Then the response status will be 200,302,404
...
Java步骤代码:

@When("^the response status will be (.*)$")
public void the_response_status_should_be(List<Integer> statusList) throws Throwable {
   //...
}
@何时(“^response status将为(.*)$”)
public void \u响应\u状态\u应为(列表状态列表)可丢弃{
//...
}

我认为这两种选择都符合你的要求。希望有帮助

可能有3个以上的值吗?@Reimeus可能!我可以将其限制为最多3个,然后检查每个参数是否未定义?好吧,您尝试的是在其当前形式下不可能的,因为step文件参数的数量始终是固定的。因此,下面的选项似乎是最好的选项。可以有3个以上的值吗?@Reimeus!我可以将其限制为最多3个,然后检查每个参数是否未定义?好吧,您尝试的是在其当前形式下不可能的,因为step文件参数的数量始终是固定的。因此,下面的选项似乎是最好的选择!谢谢:)好主意!谢谢:)这也是一个很好的答案!我很难在你们两人之间做出选择,所以我选择了第一个回答的人,但这个答案也适用于我的问题:)谢谢!不客气!不用担心。老实说,我也很喜欢@Reimeus答案,但我觉得让你知道另一个选择会很有趣:)谢谢你的+1另一个答案很完美,但很琐碎。这个方法还有一个优点:你可以在场景大纲中很好地使用它。这也是一个很好的答案!我很难在你们两人之间做出选择,所以我选择了第一个回答的人,但这个答案也适用于我的问题:)谢谢!不客气!不用担心。老实说,我也很喜欢@Reimeus答案,但我觉得让你知道另一个选择会很有趣:)谢谢你的+1另一个答案很完美,但很琐碎。这种方法还有一个优点:您可以在场景大纲中很好地使用它。