在jbehave 3示例中,我可以看到参数是“双精度”,所以我尝试使用除字符串之外的其他类型,但当我尝试添加一个布尔参数时,如下所示
public void theUserShouldBeRedirectedToHomePage(@Named("should?") boolean should)我得到一个参数类型错误:
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jbehave.scenario.steps.CandidateStep$1.perform(CandidateStep.java:225)
at org.jbehave.scenario.ScenarioRunner$FineSoFar.run(ScenarioRunner.java:112)(另外,我使用的是2.3版,而不是jbehave的3版)
我的jbehave版本有问题吗?使用布尔参数的正确方式是什么?
发布于 2012-02-24 08:44:38
我也试过这个。对于boolean/Boolean没有默认的ParameterConverter。您可以很容易地添加一个。
http://jbehave.org/reference/stable/parameter-converters.html
发布于 2014-08-13 20:17:38
如果您无论如何都要将此参数传递给其他方法,有时这样做会更容易:
public void theUserShouldBeRedirectedToHomePage(@Named("should?") 字符串应){
myNextMethod(Boolean.valueOf(should));}
发布于 2015-11-26 17:25:42
Jbehave版本3可以很好地处理Boolean。以下面的例子为例,它在我的代码中工作得很好。
@Then("I verify the response has _success as $_success and _warning as $_warning and _info as $_info and _messages as $_messages")
public void pidOrPidColorDeleteResponse(
@Named("_success") Boolean _success,
@Named("_warning") Boolean _warning,
@Named("_info") Boolean _info,
@Named("_messages") List<String> _messages) {
}用Jbehave版本2需要检查。
https://stackoverflow.com/questions/8826667
复制相似问题