簡體   English   中英

DataTable.diff(列表 <Map> )或清單 <String[]> 在黃瓜jvm中

[英]DataTable.diff( List<Map> ) or List<String[]> in cucumber-jvm

我目前正在將最初用ruby編寫的測試套件移植到java。

列表<String []>

我試圖將CSV數據移植到List<String[]>第一步

@Then("test 1")
public void test1( DataTable expectedTable ) {
  List<String[]> tableData = getCsvData( fileName );
  // I have also tried List<Map<String,String>> here.
  // when List<String[]> includes the column names in element 0, TableConverter.toTable() 
  // for List<Map<String,String>>, TableConverter.toTable() ends up with 
  // writer: { columnNames:(as provided in element 0),
  //           fieldNames: ["entry", "entry", "entry"...]
  //           fieldValues: [colName0, row1Value0, colName1, row1Value1...] }
  // and then ComplexTypeWriter.getValues() calls
  //   int index = fieldNames.indexOf(converter.map(columnName));
  // where columnName is correct, but index is evaluated as -1, so getValues() returns
  //   [, , , ,...]
  // so .diff() displays a table of empty strings.
  expectedTable.diff( tableData );
}

... cucumber-jvm無法正確顯示實際的CSV數據。

列表<Map <String,String >>

在我們的ruby實現中,其他測試步驟使用Cucumber::Ast::Table.diff! 顯示失敗原因:

failure = {'line number' => line, 'reason' => 'bad data in column 2', 'data' => column2}
failures.push failure
Cucumber::Ast::Table.new([[]]).diff!( failures, {surplus_col: true, surplus_row: true} )    unless failures.empty?

我嘗試使用java.util.Map將其移植到java,如下所示。 麻煩的是,盡管cumulage-jvm識別出空的DataTableMapList之間存在差異,但它無法正確解析(或顯示) List<Map>

Map<String,String> failure = new HashMap<String,String>();
failure.put("line number", Integer.toString(line));
failure.put("reason", "bad data in column 2");
failure.put("data", Arrays.toString(column2));

List<Map<String,String> failures = new ArrayList<Map<String,String>>();
failures.add(failure);

// We're expecting an empty list of failures, so create one to compare against.
String[] columnNames = failures.get(0).keySet().toArray(new String[]{});
ArrayList<Map<String, String>> emptyList = new ArrayList<Map<String,String>>();
HashMap<String, String> emptyData = new HashMap<String, String>();

for( String columnName : failures.get(0).keySet() ) {
    emptyData.put(columnName, null);
}

emptyList.add(emptyData);
DataTable empty = DataTable.create( emptyList, Locale.getDefault(), columnNames );

empty.diff( failures );

我已經實現了對此的支持:

https://github.com/cucumber/cucumber-jvm/pull/434

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM