问题
How to implement TestNG test suite using java instead of testng.xml. i follow following procedure but i cannot run it with the maven suefire plug in.
Please help
TestNG testNG = new TestNG();
List<XmlClass> classList =new ArrayList<XmlClass>();
List<XmlTest> testList = new ArrayList<XmlTest>();
List<XmlSuite> suiteList= new ArrayList<XmlSuite>();
List<String> suiteNameList = new ArrayList<String>();
XmlTest xmlTest= new XmlTest();
XmlSuite suite = new XmlSuite();
XmlClass xmlClass = new XmlClass();
xmlClass.setClass(bpsTestNg.class);
classList.add(xmlClass);
xmlTest.setClasses(classList);
testList.add(xmlTest);
suite.setTests(testList);
suiteList.add(suite);
suite.setName("sampleSuite1");
suiteNameList.add("sampleSuite1") ;
suite.toXml();
IConfiguration iConfiguration = null;
SuiteRunner suiteRunner= new SuiteRunner(iConfiguration,suite,".");
suiteRunner.run();
Thank You, Dharshana.
回答1:
If you're using the API, your main class is no longer a TestNG test class, just a regular Java class, so it's not surprising that Surefire no longer sees it as a test.
回答2:
Hi i resolved this issue please refer the code below
@BeforeSuite
public static void TestSuite() {
TestNG testNG = new TestNG();
List<Class> listnerClasses = new ArrayList<Class>();
List<String> suiteNameList = new ArrayList<String>();
Class[] classList = new Class[]{
ManagementClient.class,
ProcessManagementClient.class,
DeployClient.class,
RedeployClient.class};
listnerClasses.add(org.wso2.platform.test.core.PlatformTestManager.class);
listnerClasses.add(org.wso2.platform.test.core.PlatformSuiteManager.class);
testNG.setDefaultSuiteName("suite");
testNG.setListenerClasses(listnerClasses);
testNG.setTestClasses(classList);
testNG.run();
}
Thank You all for your help :)
EDIT: Improved formatting ;-)
来源:https://stackoverflow.com/questions/9003754/implementing-testng-suite-programmatically-and-executing-it-via-maven-surefire