我们有这样的故事文件(例如)
Given Something
Scenario Some scenario
When I do something blah blah
Then I get a bunch of stuff and the following data:
{transformer=FROM_LANDSCAPE}
|aField|aVal1|aVal2|aVal3|
|bField|bVal1|bVal2|bVal3|
|cField|cVal1|cVal2|cVal3|
然后在我们的步骤类中:
@Then("I get a bunch of stuff and the following data:$myData")
public void verifyData(ExamplesTable myData) {
List<SomeDataClass> myDataList = myData.getRowsAs(SomeDataClass.class);
// do something
}
SomeDataClass通常看起来像:
public class SomeDataClass {
private int aField;
private String bField;
private String cField;
// getters/setters ...
}
但是我处于这样的数据类中:
public class NewDataClass {
private int aField;
private String bField;
private Set<SomeObj> cField;
//...
}
在这种情况下,我将一组(一组)事物作为字段。如何使用表格在上述故事语法中表示这一点?也许有更好的方法?
最佳答案
JBehave支持mapping parameters to custom types。
提供的示例将具有以下语法。
故事文件:
Given Something
Scenario Some scenario
When I do something blah blah
Then I get a bunch of stuff and the following data:
{transformer=FROM_LANDSCAPE}
|aField|aVal1|aVal2|aVal3|
|bField|bVal1|bVal2|bVal3|
|cField|cVal1|cVal2|cVal3|
步骤实施:
@Then("I get a bunch of stuff and the following data:$myData")
public void verifyData(List<NewDataClass> myData) {
// step logic
// ...
}
NewDataClass:
import org.jbehave.core.annotations.AsParameters;
@AsParameters
public class NewDataClass {
private int aField;
private String bField;
private Set<SomeObj> cField;
// getters & setters
// ...
}
关于java - Jbehave示例表数组/列表作为参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51743575/