0
如果在黄瓜步骤的任一末端,在黄瓜步骤中定义可选参数很容易。怎么样,如果它在中间,如:匹配是否可以在黄瓜步骤中定义可选参数
@When("^(in)?active update message is received for (\\D+)(?: (\\d))? (\\D+) (\\d+)$")
public void testStepDef(
final String optionalInactive,
final String someWord,
final int optionalInt,
final String someOtherWord,
final int id) {
例模式:
* inactive update message is received for word anotherword 1 // not ok
* active update message is received for word 1 anotherword 7 // ok
* inactive update message is received for word 7 anotherword 3 // ok
从这些例子中,只有后者的2工作;第一个,没有定义optionalInt
,失败。正则表达式匹配,但方法invokation失败:
cucumber.runtime.CucumberException: Failed to invoke cucumber.stepdefs.common.CommonStepDefs.testStepDef(String,String,int,String,int) in file:/step/file/location
任何方法来解决此限制?
我不知道这是否是问题,但是您正在使用原语作为参数。一个int不能为null。如果您尝试使用Integer类型,那该怎么办?无论如何,如果黄瓜不能胜任,我可能只是将更多的解析放到步骤中。 –