我们有这样的故事文件(例如)
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;
//...
}
在这种情况下,我将一组(一组)事物作为字段。如何使用表格在上述故事语法中表示这一点?也许有更好的方法?
答案 0 :(得分:1)
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
// ...
}
答案 1 :(得分:0)
示例故事文件片段:
Given I am on the add a new user page
When I enter <firstName> <lastName> <address> <city> <state> and <zip>
And I click the Ok button
Then the new user is added
Examples:
firstName|lastName|address |city |state|zip
Bill |Hileman |123 Main Street|Yourtown|FL |12345
Art |VanDelay|321 Elm Drive |MyTown |PA |54321
步骤文件代码:
@When("I enter <firstName> <lastName> <address> <city> <state> and <zip>")
public void whenIEnterdata(@Named("firstName") String firstName,
@Named("lastName") String lastname,
@Named("address") String address,
@Named("city") String city,
@Named("state") String state,
@Named("zip") String zip) {
// your step code here
}