0

在 jbehave 3 示例中,我可以将参数视为“double”,因此我尝试使用字符串以外的其他类型,但是当我尝试添加这样的布尔参数时

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 版本有问题吗?哪个是使用布尔参数的正确方法?

4

3 回答 3

1

我也试试这个。boolean/Boolean 没有默认的 ParameterConverter。您可以轻松添加一个。

http://jbehave.org/reference/stable/parameter-converters.html

于 2012-02-24T00:44:38.463 回答
0

如果您无论如何都要将此参数传递给其他方法,有时这样做更容易:

public void theUserShouldBeRedirectedToHomePage(@Named("should?") String should){

myNextMethod( Boolean.valueOf(should) ); }

于 2014-08-13T12:17:38.490 回答
0

Jbehave 版本 3 可以很好地与布尔值配合使用。以下面的示例为例,它在我的代码中运行良好。

@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 Version 2 需要检查。

于 2015-11-26T09:25:42.047 回答