cucumber-jvm:比较忽略某些列的数据表

时间:2016-08-01 09:59:36

标签: cucumber-jvm

我想将特征文件中的DataTable与页面上的一个进行比较,但是想要忽略某些日期时间字段。有没有直接的方法来做到这一点?感谢。

1 个答案:

答案 0 :(得分:0)

将DataTable与对象列表进行比较时,将忽略缺少的字段,例如:

static class SomeBean {
    String field1;
    String field2;
    String field3;

    public SomeBean(String field1, String field2, String field3) {
        this.field1 = field1;
        this.field2 = field2;
        this.field3 = field3;
    }
}

    DataTable expectationBeanTable = DataTable.create(Arrays.asList(
            new SomeBean("value1", "value2", null)
    ));

    List<SomeBean> actual = Arrays.asList(
            new SomeBean("value1", "value2", "value3")
    );
    expectationBeanTable.diff(actual); //OK

    DataTable expectationStringTable = DataTable.create(Arrays.asList(
            Arrays.asList("field1", "field2"),
            Arrays.asList("value1", "value2")
    ));

    expectationStringTable.diff(actual); //Also OK

在比较两个DataTable时不会起作用:

expectationStringTable.diff(DataTable.create(actual));

java.lang.IllegalArgumentException: Tables must have equal number of columns:
      | field1 | field2 |
      | value1 | value2 |

      | field1 | field2 | field3 |
      | value1 | value2 | value3 |