如何在 Cucumber-JVM 中用一个 "Then" 步骤匹配任意数量的条件?

How to match any number of conditions with one "Then" step in Cucumber-JVM?

在 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"

我需要为每个 "or" 编写一个匹配器吗?

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

例如,如何将这些组合成一个函数?:

@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);
}

这可能吗?

谢谢!

鉴于值列表 您可以映射到具有包含

的特征文件的 List
...
Then the response status will be one of the following
    | response status | 
    | 200             |
    | 302             |
    | 404             |
....

使用 Cucumber 代码

@Then(^the response status will be one of the following$)
public void doResponseStuff(List<String> responses){
   // use response codes...
}    

@Reimeus 好的答案的替代方法,您还可以在步骤定义中匹配 List<Integer>

特征定义:

...
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 {
   //...
}

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