在黄瓜中,我可以将表解析为对象列表,例如:
public class Model {
public String a;
public String b;
public String c;
}
我的专题文件:
Scenario: Example
Given examples
|a |b |c |
|lsj |fjsldkf|fljs |
|fjsdfj|jfkskjl|fsjls|
我的继续课程:
@Given("$examples$")
public void examples(List<Model> list){}
当我的模型对象引用其他对象时,我该怎么做呢,例如:
public class SubModel{
public String subA;
public String subB;
}
public class Model {
public String a;
public String b;
public String c;
public SubModel subModel1;
public SubModel subModel2;
}
在这种情况下,如何编写表格以便解析模型列表?
答案 0 :(得分:0)
仅按以下方式使用。会起作用
@Given("^examples$")
public void examples(DataTable sampleTable) {
Map<String, String> sampleMap = new HashMap<>();
DataTableRow header = sampleTable.getGherkinRows().get(0);
DataTableRow value = sampleTable.getGherkinRows().get(1);
for (String key : header.getCells()) {
sampleMap.put(key, value.getCells().get(header.getCells().indexOf(key)));
}
client.setSampleDetails(sampleMap);
}