【问题标题】:@DataProvider + @Factory + Hashmaps@DataProvider + @Factory + 哈希图
【发布时间】:2018-11-17 12:29:18
【问题描述】:

在使用 @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;
}

【问题讨论】:

    标签: automation testng factory dataprovider


    【解决方案1】:

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-03-21
      • 2022-12-10
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多