I need to run a programe before knowing which suit of test(define in testng.xml)开发者_StackOverflow need to be trigger.
How to solve this problem? how to trigger testNG in run time?
Have you looked at TestNG's programmatic API?
Below code you have to put it in main method. You can run the class as regular java file.
XmlSuite suite = new XmlSuite();
suite.setName("TmpSuite");
XmlTest test = new XmlTest(suite);
test.setName("TmpTest");
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
//MyTestListener is custom listner if any
TestListenerAdapter listener = new MyTestListener();
tng.addListener(listener);
tng.setXmlSuites(suites); //if any suits
tng.run();
Hi You can add listeners ie- suitelistner , testlistner and report listener for better control over your test.
精彩评论