简体   繁体   English

JBehave步骤中的自定义类型列表

[英]List of custom type in JBehave step

Given a parameter converter 给定参数转换器

@AsParameterConverter
public MyType toMyType(String myTypeString) {
}

When I try to run a test having a step 我尝试进行有步骤的测试时

@Given("a custom step with a $vals")
public void list(List<MyType> vals) {
}

Then it should run, but it fails with the following message: 然后它应该运行,但是失败,并显示以下消息:

No parameter converter for interface java.util.List
org.jbehave.core.steps.ParameterConverters$ParameterConvertionFailed: No parameter converter for interface java.util.List

To the best of my knowledge, JBehave does not accept arrays as parameters. 据我所知,JBehave不接受数组作为参数。 You should, instead, pass the variables individually. 您应该改为分别传递变量。 If there are too many, then perhaps a different approach should be considered. 如果太多,则应考虑使用其他方法。 I would also recommend using the <> delimiters for parameters instead of $ as I have experienced problems with legacy code using $ finding "duplicate steps" that were not duplicates, but went away when changed to <>. 我还建议对参数使用<>分隔符而不是$,因为我在使用$查找“重复步骤”(不是重复项,但更改为<>时消失了)的旧代码时遇到了旧代码问题。 It is not the cause of your reported error, but I would think you would also have to use the @Named("vals") declaration before the defined parameter type and variable. 这不是报告错误的原因,但我认为您还必须在定义的参数类型和变量之前使用@Named(“ vals”)声明。

I believe the reason that JBehave would not be able to support arrays as parameters is because it would have no way of knowing what to pass. 我相信JBehave之所以无法将数组作为参数来支持,是因为它无法知道要传递的内容。 You might think that perhaps it is the only parameter(s) in the scenario, but what if there were other variables, ie vals might be employee info (first name, last name, etc.) and then another step in the same scenario needs, say, a URL. 您可能会认为这可能是场景中的唯一参数,但是如果还有其他变量,例如val可能是员工信息(名字,姓氏等),然后需要在同一场景中执行另一步骤怎么办(例如URL)。 How could JBehave determine which variables in the list of Examples to pass as "vals" and where to locate "URL" or any other variable? JBehave如何确定示例列表中的哪些变量作为“ vals”传递以及在何处定位“ URL”或任何其他变量?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM