How to create TestSuite class in TestNG without xm

2019-07-18 09:01发布

问题:

I Want to run Sanity.java and regression.java together so I've created TestSuite.java in junit and it is working. Now I want create the same using TestNG, plz help me..

Below is my junit framework code:

package com.abc.def;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import com.auto.tests.abc1;
import com.auto.tests.abc2;
import com.auto.tests.abc3;
import com.auto.tests.abc4;


@RunWith(Suite.class)
@Suite.SuiteClasses({abc1.class, abc2.class,abc3.class,abc4.class})
public class abcTestSuite {

}

回答1:

You can run testNG test classes from your program. See example below

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

You can set the test classes you want to run in your suite class by using above code. Also for more details on running testNG programatically please refer this link