简体   繁体   English

黄瓜 6 未定义的自定义步骤

[英]Cucumber 6 undefined custom step

I am upgrading Cucumber version in my project and custom configuration changed between versions 4 and 6.我正在升级我的项目中的 Cucumber 版本,并且自定义配置在版本 4 和 6 之间发生了变化。

I've registered a custom keyword for Parameter Type.我已经为参数类型注册了一个自定义关键字。

Everything works, step passes and the value is generated but the step is still marked as undefined .一切正常,步骤通过并生成值,但步骤仍标记为 undefined

I use Intellij IDEA and Cucumber plugin for Java Is it a plugin problem or somewhere in y code?为 Java使用 Intellij IDEA 和Cucumber 插件这是插件问题还是代码中的某个地方?

Cucumber step:黄瓜步骤:

When generate uniqueRandom(5) for test

在此处输入图片说明

Java step: Java步骤:

@When("generate {unique_random} for test")
public void testStep(int randomNumber) {
    log.info(String.valueOf(randomNumber));
}

Parameter Type registry:参数类型注册表:

@ParameterType(name = "unique_random", value = "uniqueRandom\\([0-9]+\\)")
public Integer randomNumber(String original) {
    return ... // some logic of creation
}

Cucumber version: 6.8.1黄瓜版本: 6.8.1

Is it possible from my side to do something with this warning?我这边有可能对这个警告做些什么吗?

Looks like there is an issue with Cucumber API and Cucumber Plugin.看起来 Cucumber API 和 Cucumber Plugin 存在问题。

I changed my Parameter Type registration method我改变了我的参数类型注册方法

from:从:

@ParameterType(name = "unique_random", value = "uniqueRandom\\([0-9]+\\)")
public Integer randomNumber(String original) {
    return ... // some logic of creation
}

to

@ParameterType(value = "uniqueRandom\\([0-9]+\\)")
public Integer unique_random(String original) {
    return ... // some logic of creation
}

This solution is described in the documentation of @ParameterType.name()此解决方案在@ParameterType.name()的文档中有所描述

Name of the parameter type.参数类型的名称。 This is used as the type name in typed expressions.这用作类型表达式中的类型名称。 When not provided this will default to the name of the annotated method.如果未提供,这将默认为带注释的方法的名称。

The plugin doesn't resolve the parameter name in the annotation but as a method name.该插件不会解析注释中的参数名称,而是将其解析为方法名称。

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

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