从 info.cukes 更新到 io.cucumber 后,Cucumber 不允许无效枚举

Cucumber doesn't allow invalid enums after update from info.cukes to io.cucumber

我正在将旧版本的黄瓜从软件包 info.cukes 迁移到最新的 io.cucumber。我注意到旧版本允许无效的枚举值作为测试参数和 returns null 但最新版本抛出异常 io.cucumber.core.exception.CucumberException: Could not convert arguments for step...

迁移后如何在测试中保留旧行为?下面的示例代码重现错误。

#  feature file with test definition
Feature: Parsing enums

  Scenario: Parse enum using empty string
    Given I'm parsing enum ""
//Step definition code
    @Given("^I'm parsing enum \"(.*?)\"$")
    public void i_m_parsing_enum(MyEnum arg1) throws Throwable {
        System.out.println(arg1); // should print null but throws exception after library upgrade
    }
//Simple enum
public enum MyEnumo {
    abc, def
}

根据@luis-iñesta 评论,我使用 @ParameterType 注释编写了简单的 try-catch:

    @ParameterType("[a-z]*")
    public MyEnum myEnum(String name) {
        try {
            return MyEnum.valueOf(name);
        } catch (IllegalArgumentException e){
            return null;
        }
    }

    @Given("I'm parsing enum \"{myEnum}\"")
    public void i_m_parsing_enum(MyEnumo arg1) throws Throwable {
        System.out.println(arg1);
    }

在这种情况下有效,但我仍然想知道是否有一些开关或参数可以保持旧的黄瓜行为。