编程语言
首页 > 编程语言> > java – Cucumber-JVM 3 – io.cucumber.datatable.UndefinedDataTableTypeException

java – Cucumber-JVM 3 – io.cucumber.datatable.UndefinedDataTableTypeException

作者:互联网

我在我的pom.xml中从Cucumber-JVM 2.4.0更新到3.0.2,并且DataTables开始抛出此异常:

io.cucumber.datatable.UndefinedDataTableTypeException: Can’t convert
DataTable to List< jcucumberng.steps.pojos.Income >. Please register a
DataTableType with a TableEntryTransformer or TableRowTransformer for
class jcucumberng.steps.pojos.Income

我把所有的进口都改成了

import io.cucumber.datatable.DataTable;

我做了一个mvn clean install并且编译成功,但更新后涉及DataTables的步骤不再有效.

当前代码:

// Feature
When I Enter My Regular Income Sources
  | name   | amount | frequency     |
  | Salary | 25000  | every 2 weeks |


// Stepdef
@When("^I Enter My Regular Income Sources$")
public void I_Enter_My_Regular_Income_Sources(DataTable dataTable) throws Throwable {
    List<Income> incomes = dataTable.asList(Income.class);

    // More code    
}


// Custom type
public class Income {

    private String name = null;
    private String amount = null;
    private String frequency = null;

    public Income(String name, String amount, String frequency) {
        this.name = name;
        this.amount = amount;
        this.frequency = frequency;
    }

    // Getters and setters
}

有没有一种在Cucumber-JVM v3.x.x中使用DataTables的新方法?

更新:
enter image description here

解决方法:

它已经彻底改造了. XStream已被删除,因此早期的代码将无法正常工作.

您需要为数据表和参数转换添加逻辑.请参阅这些 – https://github.com/cucumber/cucumber/tree/master/datatablehttps://github.com/cucumber/cucumber/tree/master/cucumber-expressions.将类代码放在glue选项中定义的包中.

public class Configurer implements TypeRegistryConfigurer {

    @Override
            public void configureTypeRegistry(TypeRegistry registry) {

    registry.defineDataTableType(new DataTableType(Income.class, new TableEntryTransformer<Income>() {
                    @Override
                    public Income transform(Map<String, String> entry) {
                        return new Income(entry.get("name"),entry.get("amount"),entry.get("frequency"));
                    }
                }));
            }

            @Override
            public Locale locale() {
                return Locale.ENGLISH;
            }

        }

更新
进口……并非所有都是必需的,保持相关的内容

import cucumber.api.TypeRegistry;
import cucumber.api.TypeRegistryConfigurer;
import io.cucumber.cucumberexpressions.ParameterType;
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableType;
import io.cucumber.datatable.TableCellTransformer;
import io.cucumber.datatable.TableEntryTransformer;
import io.cucumber.datatable.TableRowTransformer;
import io.cucumber.datatable.TableTransformer;

标签:cucumber-jvm,java,datatable,cucumber
来源: https://codeday.me/bug/20190910/1799623.html