猿问

Jbehave 示例表数组/列表作为参数

我们有这样的故事文件(说)


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;


    //...


}

在这种情况下,我有一个集合(集)作为一个字段。如何使用表格在上面的故事语法中表示这一点?也许有更好的方法?


陪伴而非守候
浏览 115回答 2
2回答

UYOU

JBehave 支持将参数映射到自定义类型。提供的示例将具有以下语法。故事档案:Given SomethingScenario Some scenarioWhen I do something blah blahThen 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) {&nbsp; &nbsp; // step logic&nbsp; &nbsp; // ...}新数据类:import org.jbehave.core.annotations.AsParameters;@AsParameterspublic class NewDataClass {&nbsp; &nbsp; private int aField;&nbsp; &nbsp; private String bField;&nbsp; &nbsp; private Set<SomeObj> cField;&nbsp; &nbsp; // getters & setters&nbsp; &nbsp; // ...}

慕勒3428872

示例故事文件片段:Given I am on the add a new user pageWhen I enter <firstName> <lastName> <address> <city> <state> and <zip>And I click the Ok buttonThen the new user is addedExamples:firstName|lastName|address&nbsp; &nbsp; &nbsp; &nbsp; |city&nbsp; &nbsp; |state|zipBill&nbsp; &nbsp; &nbsp;|Hileman |123 Main Street|Yourtown|FL&nbsp; &nbsp;|12345Art&nbsp; &nbsp; &nbsp; |VanDelay|321 Elm Drive&nbsp; |MyTown&nbsp; |PA&nbsp; &nbsp;|54321步骤文件代码:@When("I enter <firstName> <lastName> <address> <city> <state> and <zip>")public void whenIEnterdata(@Named("firstName") String firstName,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Named("lastName") String lastname,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Named("address") String address,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Named("city") String city,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Named("state") String state,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Named("zip") String zip) {&nbsp; &nbsp; // your step code here}
随时随地看视频慕课网APP

相关分类

Java
我要回答