Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call testng.xml from java main method?

I have testng.xml file created. Is there any way to run this file from java main method?

Something like -

Class test {
  public static void main ( String [ ] args) 
  {
    Run(testng.xml);
  }
}
like image 485
Deepak Avatar asked Apr 24 '14 15:04

Deepak


1 Answers

This work for me. More details here.

// Create object of TestNG Class
TestNG runner=new TestNG();

// Create a list of String 
List<String> suitefiles=new ArrayList<String>();

// Add xml file which you have to execute
suitefiles.add("C:\\Automation Test\\Git\\vne_automation\\testng.xml");

// now set xml file for execution
runner.setTestSuites(suitefiles);

// finally execute the runner using run method
runner.run();

Hope this helps!

like image 70
Huy Hóm Hỉnh Avatar answered Oct 21 '22 23:10

Huy Hóm Hỉnh