将Cucumber表实例化为对象

时间:2016-03-28 14:13:49

标签: java cucumber

我在将数据表映射到Cucumber中的类型时遇到了一些麻烦。 Cucumber希望pojos与stepdef共处一地。但是,如果它在另一个模块中呢?我该如何进行映射?我可以添加一条线给我的跑步者吗?

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

2 个答案:

答案 0 :(得分:0)

你能得到一个更小的例子吗?我觉得您使用的数据类型必须与步骤位于同一位置,这听起来很奇怪。只要该类型在类路径上可用,它应该在我现在可以理解的范围内工作。

与此同时,我们已经了解到xstream包在某些情况下会出现意外情况,并且可能会在即将推出的Cucumber版本中被替换。

看看你是否可以让这个样本起作用,http://www.thinkcode.se/blog/2014/06/30/cucumber-data-tables

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

答案 1 :(得分:0)

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

相关问题