TestNG: More than one @DataProvider for one @Test

后端 未结 4 1382
失恋的感觉
失恋的感觉 2021-02-02 10:27

I\'m using TestNG for Eclipse.

Is it possible to give two data providers step by step to the same test-function?

I co

4条回答
  •  有刺的猬
    2021-02-02 11:12

    No, but nothing stops you from merging these two data providers into one and specifying that one as your data provider:

    public Object[][] dp1() {
      return new Object[][] {
          new Object[] { "a", "b" },
          new Object[] { "c", "d" },
      };
    }
    
    public Object[][] dp2() {
      return new Object[][] {
          new Object[] { "e", "f" },
          new Object[] { "g", "h" },
      };
    }
    
    @DataProvider
    public Object[][] dp() {
      List result = Lists.newArrayList();
      result.addAll(Arrays.asList(dp1()));
      result.addAll(Arrays.asList(dp2()));
      return result.toArray(new Object[result.size()][]);
    }
    
    @Test(dataProvider = "dp")
    public void f(String a, String b) {
      System.out.println("f " + a + " " + b);
    }
    

提交回复
热议问题