开发者

how to triger testng by testng.xml, after determing by other test which testng.xml need to be run

开发者 https://www.devze.com 2023-04-08 09:42 出处:网络
I need to run a programe before knowing which suit of test(define in testng.xml)开发者_StackOverflow need to be trigger.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消