在使用Data Provider的Test方法之后,我怎样才能每次都执行一些测试

时间:2016-06-07 19:16:58

标签: selenium-webdriver testng testng-dataprovider

   @Test(dataProvider="LInData",dataProviderClass=LInDataProvider.class)
public void testLIn(String fname) throws InterruptedException// return 3 fname and this test executed 10 times
{
    System.out.println("test start");

    System.out.println("fname:"+fname);     

        System.out.println("test completed");
}

@Test(dataProvider="LInData",dataProviderClass=LInDataProvider.class)
public void me(String fname,String lname,String em,String pass) 
{
   System.out.println("Other tests");
}

它产生了这个结果:

FNAME:安迪

FNAME:插孔

FNAME:棕榈

其他测试

但我需要一个以下,请告诉我如何获得低于o / p:

FNAME:安迪

其他测试

FNAME:插孔

其他测试

FNAME:棕榈

其他测试

1 个答案:

答案 0 :(得分:1)

这是factories的完美案例!

public class MyTest {

   private final String fname
   private final String lname;
   private final String em;
   private final String pass;

   @Factory(dataProvider="LInData",dataProviderClass=LInDataProvider.class)
   public MyTest(String fname, String lname, String em, String pass) {
      // init attributes
   }     

   @Test
   public void testLIn() throws InterruptedException // return 3 fname and this test executed 10 times
    {
        System.out.println("test start");        
        System.out.println("fname:" + fname);
        System.out.println("test completed");
    }

    @Test(dependsOnMethods = {"testLIn"})
    public void me() {
       System.out.println("Other tests");
    }
}