将 Cucumber table 实例化为对象时出错

Error instantiating Cucumber table to object

我在将数据表映射到 Cucumber 中的类型时遇到了一些问题。 Cucumber 希望 pojos 与 stepdefs 位于同一位置。但是如果它在另一个模块中呢?我将如何进行映射?我可以添加一条线到我的跑步者吗?

Given an appointment
    |poid|advisorCrewId|appointmentType|
    |1234|036264|wxyz|
When blah blah
Then blah blah

我正在使用一种我已经准备好的类型

public class Appointment implements Serializable {

        private static final long serialVersionUID = -1456832796215683035L;

        private Integer poid;

        private String advisorCrewId;

        private String appointmentType;

        public Appointment(Integer poid, String advisorCrewId, String appointmentType) {
            this.poid = poid;
            this.advisorCrewId = advisorCrewId;
            this.appointmentType = appointmentType;
        }

        public Integer getPoid() {
            return poid;
        }

        public String getAdvisorCrewId() {
            return advisorCrewId;
        }

        public String getAppointmentType() {
            return appointmentType;
        }

    }

但是当我尝试像这样在 Cucumber 中访问它时

@Given("^an appointment$")
    public void method_name(List<Appointment> appointments) {
        this.appointments = appointments;
        poid = appointments.get(0).getPoid();
    }

我收到这个错误。我认为,为了让数据表与类型匹配,您只需要让成员变量匹配即可。我还缺少其他步骤吗?

 cucumber.runtime.CucumberException: cucumber.deps.com.thoughtworks.xstream.converters.ConversionException: Cannot construct com.blahblah.Appointment

你能得到一个更小的例子吗?您使用的数据类型必须与步骤放在一起,这对我来说听起来很奇怪。只要该类型在类路径上可用,就我目前的理解而言,它应该可以工作。

同时,已了解 xstream 包在某些情况下会出现意外行为,它可能会在即将发布的 Cucumber 版本中被替换。

看看你能否让这个示例工作,http://www.thinkcode.se/blog/2014/06/30/cucumber-data-tables

如果你能让它工作,将使用的数据类型移动到另一个包,看看单独移动会破坏它。

原来这是一个 maven 问题。它试图实例化一个接口,而不是 class,这就是它抛出这个问题的原因