如何在我的 Cucumber BDD 步骤定义中使“the”可选?

Kat*_*tie 4 bdd cucumber gherkin cucumber-jvm cucumber-java

我想匹配以下 BDD 之一:

Then the response status should be "200"
Then response status should be "200"
Run Code Online (Sandbox Code Playgroud)

我想让“the”可选。我希望这两个规则映射到同一步骤。

这是我的尝试,但它不起作用:

@Then("^(?:the | )response status should be \"([^\"]*)\"$")
public void the_response_status_should_be(String arg1) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

jga*_*uld 5

这可能有效..."^(?:the )*response status should be \"([^\"]*)\"$"

  • 这不起作用,但添加 `?:` 却起作用了!我会编辑你的答案;D (2认同)