Eliminating the need for testng.xml when running Java unit tests in TestNG

I find it necessary to maintain and edit testng.xml despite having annotations as a limitation of TestNG. Is it possible to automate the generation of testng.xml, or eliminate the need for it entirely when running unit tests?

+3


source to share


1 answer


From testng.org documentation: "You can call TestNG from your own programs very easily":

TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();

      

This example creates a TestNG object and runs the test class Run2. It also adds a TestListener.



Ref:

You can read more about this here: http://testng.org/
one Stack Discussion on simillar topic
Working example class on Github

+2


source







All Articles