编程语言
首页 > 编程语言> > java-如何在黄瓜中使用可选参数

java-如何在黄瓜中使用可选参数

作者:互联网

我想要相同的Gherkin句子(有参数和无参数):

小黄瓜与参数:

When a 'notify' message is sent to the green box with the properties.
 |type|message|
 |error|The error message|

没有参数的小黄瓜:

When a 'notify' message is sent to the green box with the properties.

Java(黄瓜):

@When("^a '(.*)' message is sent to the green box with the properties.$")
public void hello(String name, List<GherkinCondition> conditions) {
    ...
}

我有一个错误,因为用2个参数声明了Java方法,并且在“无参数”的情况下,我只有一个.

堆栈跟踪:

cucumber.runtime.CucumberException: Arity mismatch: Step Definition 'steps.CommonSteps.hello(String,GherkinCondition>) in file:/C:/workspace/xxxxx/java/target/classes/' with pattern [^a '(.*)' message is sent to the green box with the properties.$] is declared with 2 parameters. However, the gherkin step has 1 arguments [notify]. 

解决方法:

黄瓜步骤定义不支持可选参数.

您可以编写两个不同的步骤定义,也可以为第二种情况提供一个空的数据表.

When a 'notify' message is sent to the green box with the properties.
 |type|message|

甚至

When a 'notify' message is sent to the green box with the properties.
     |||

标签:cucumber,gherkin,java
来源: https://codeday.me/bug/20191118/2026184.html