Dynamic @Test generation in TestNG

1.1k views Asked by At

I have following test method in DummyFT.java file. All I do is just change the parameters and do another test.

public class DummyFT extends BaseClass{

  @Test
  public  void DummyMethod1() throws Exception  {
      testSuite = project.getTestSuiteByName( "Dummy_1_Regression" );   
      testCase = testSuite.getTestCaseByName( "Dummy_TestCase_1 " );            
      runner = testCase.run( new PropertiesMap(), false ); 
      Assert.assertEquals( Status.FINISHED, runner.getStatus() );
  }

  @Test
  public  void DummyMethod2() throws Exception  {
      testSuite = project.getTestSuiteByName( "DummyRegression2" ); 
      testCase = testSuite.getTestCaseByName( "Dummy_TC_2" );
      runner = testCase.run( new PropertiesMap(), false ); 
      Assert.assertEquals( Status.FINISHED, runner.getStatus() ); 
  }

}

Now I just want to create a method which basically loop this set of @Test method and Generate proper TestNG report in detail for each of the Test Method.

I want to pass this parameters (TestCase,TestSuite,Method Name) from CSV file

How can I do this?

1

There are 1 answers

0
peetya On

Read your parameters from the CSV file and pass them to your @Test by using DataProvider.

Doc: http://testng.org/doc/documentation-main.html#parameters-dataproviders