Search This Blog

Thursday, February 4, 2016

Run TestNG programmatically from Eclipse


Make sure your testng.xml is in some folder and it is used as shown below.


package initialize;

import java.util.ArrayList;
import java.util.List;

import org.testng.TestListenerAdapter;
import org.testng.TestNG;

public class test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
 TestNG testng = new TestNG();
 
   TestListenerAdapter tla = new TestListenerAdapter();
   List<String> testFilesList = new ArrayList<String>();
   testFilesList.add(".\\resources\\testng.xml");
   System.out.println(System.getProperty("user.dir"));
testng.setTestSuites(testFilesList); //you can addd multiple suites either here by adding multiple files or include all suites needed in the testng.xml file
       testng.setUseDefaultListeners(false);
       testng.addListener(tla);
       testng.run();
}

}



No comments:

Post a Comment