开发者

several dataProvider per one Test in TestNG

I want run same tests for different implementations. In this case I should provide two dataProvider. One for implementations and other for extra data. So I wrote smt like

@DataProvider(name = "ind")
public开发者_开发技巧 Object[][] indexes(){
    return new Object[][]{{1}, {2.5}};
}

@DataProvider(name = "str")
public Object[][] strings(){
    return new Object[][]{{"a11", "a12"}, {"a21", "a22"}};
}

 public Object[][] decart(Object[][] a1, Object[][] a2){
    List<Object[]> rez = new LinkedList();
    for(Object[] o : a1){
        for(Object[] o2 : a2){
            rez.add(concatAll(o, o2));
        }
    }
     return rez.toArray(new Object[0][0]);
}

//in future, probably, I will need do decart for varargs two.
public static <T> T[] concatAll(T[] first, T[]... rest) {
  int totalLength = first.length;
  for (T[] array : rest) {
    totalLength += array.length;
  }
  T[] result = Arrays.copyOf(first, totalLength);
  int offset = first.length;
  for (T[] array : rest) {
    System.arraycopy(array, 0, result, offset, array.length);
    offset += array.length;
  }
  return result;
}

@DataProvider(name = "mixed")
public Object[][] mixed(){
    return decart(indexes(),  strings());
}


@Test(dataProvider = "mixed")
public void someTest(Number i, String s1, String s2){
    System.out.println(i + "\t" + s1 + "\t" + s2);
}

But this code seems very unnatural.. I think I've done it in wrong way. How I should do thinks like this?


No, that's pretty much it: if you want to combine several data providers, you create another data provider that calls the others and merges the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜