@DataProvider + @Factory +哈希图

时间:2018-11-17 12:29:19

标签: automation testng factory dataprovider

@Factory@DataProvider一起使用时遇到编译错误。 尝试将hashmap映射到我的dataprovider,并想先运行我的所有测试用例,然后再进行下一个testdata行,因此尝试使用@Factory

HashMap < String, String testdata = new HashMap < String, String();


@Test
private void test_01() {
 System.out.println(testdata.get("-some-hashmap-key-"));
}

@DataProvider
public static Object[][] getDataSet() {
 int i = 0;
 Object[][] dataSet = new Object[2][1];
 HashMap < String, String > rowValuesMap = new HashMap();
 for (-some logic - ) {
  for (-some logic - ) {
   dataSet[i][0] = rowValuesMap;
  }
  i++;
 }
 return dataSet;
}

@Factory(dataProvider = "getDataSet")
public MyTestFile(HashMap < String, String testdata) {
 this.testdata = sheetdata;
}

1 个答案:

答案 0 :(得分:0)

HashMap声明在所有地方都是错误的。试试这个

HashMap < String, String > testdata = new HashMap < String, String > ();

@Test
private void test_01() {
 System.out.println(testdata.get("-some-hashmap-key-"));
}

@DataProvider
public static Object[][] getDataSet() {
 int i = 0;
 Object[][] dataSet = new Object[2][1];
 HashMap < String, String > rowValuesMap = new HashMap < String, String > ();
 for (-some logic - ) {
  for (-some logic - ) {
   dataSet[i][0] = rowValuesMap;
  }
  i++;
 }
 return dataSet;
}

@Factory(dataProvider = "getDataSet")
public MyTestFile(HashMap < String, String > testdata) {
 this.testdata = sheetdata;
}