Cucumber 如何制作;";在我的BDD步骤定义中是可选的吗?

Cucumber 如何制作;";在我的BDD步骤定义中是可选的吗?,cucumber,bdd,cucumber-jvm,gherkin,cucumber-java,Cucumber,Bdd,Cucumber Jvm,Gherkin,Cucumber Java,我想匹配以下BDD之一: Then the response status should be "200" Then response status should be "200" 我想使“the”成为可选的。我希望这两条规则映射到同一步骤 这是我的尝试,但没有成功: @Then("^(?:the | )response status should be \"([^\"]*)\"$") public void the_response_status_should_be(String arg1)

我想匹配以下BDD之一:

Then the response status should be "200"
Then response status should be "200"
我想使“the”成为可选的。我希望这两条规则映射到同一步骤

这是我的尝试,但没有成功:

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

这可能有用<代码>“^(?:响应状态应为\”([^\“]*)\“$”

使用Cucumber表达式,只需在可选文本周围加上如下括号即可轻松完成:

(the )response status should be "200"

这不起作用,但添加
?:
起作用了!我将编辑您的答案;D