How to create a executable jar file for Testng and the runnnig point should be the Xml file
Solution 1
Use Eclipse Export Wizard. While exporting, select "Create Runnable Jar" and select the class which is entry point (which contains main
method) of your project.
This class will have main
method which will read XML and execute the testcases
Solution 2
Here is the better way to do it. But thanks anyways sanbhat.
You can just create a main method which will have list of all test classes to be executed as follows:
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { test_start.class });
testng.addListener(tla);
testng.run();
}
Here is the reference URL from the official testng website.
http://testng.org/doc/documentation-main.html#running-testng-programmatically
Cheers!
Solution 3
You can create a main method like below and can execute it
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("c:/tests/testng1.xml");//path to xml..
suites.add("c:/tests/testng2.xml");
testng.setTestSuites(suites);
testng.run();
}
mannu singh
Updated on July 05, 2022Comments
-
mannu singh almost 2 years
I am currently working on the selenium web driver and testng on Eclipse IDE. I usually run the test from the XML file that i have created which runs all the methods in the eclipse.
Now i want to create a simple executable jar which should do the same i.e its running point should be the XML file so that each test is executed .
I am trying hard on this. Please give me some advice on how to go further with it
-
AndroidDev about 9 yearsGreat Solution. Thank you.
-
Kimball Robinson almost 9 yearsTo use an xml configuration instead of directly choosing classes to run, see this answer: stackoverflow.com/a/23287848/116810
-
saravana about 7 yearsGetting unable to find testng.xml when run from command prompt. XML is in my runnable jar. Any help??
-
Bits Please over 5 yearsI did this to start testNG when Javafx button is clicked. It works in eclipse but doesnt work when application is deployed as Jar file.
-
Joe Caruso about 4 yearsUnnecessarily complicated
-
Joe Caruso about 4 yearsThis should be the correct answer since it was about running an xml file