CppNoob
CppNoob

Reputation: 2390

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

I find the need to maintain and edit testng.xml despite the availability of annotations as a limitation of TestNG. Is it possible to either automate the generation of testng.xml, or completely eliminate the need for it while running unit tests?

Upvotes: 3

Views: 92

Answers (1)

Chandan Nayak
Chandan Nayak

Reputation: 10877

From testng.org documentation: "You can invoke 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 it Here: http://testng.org/
Here is one Stack Discussion on the simillar topic
A working example class on Github

Upvotes: 2

Related Questions