更改:
Class cls = Class.forName("TestSuite.TestCases.AddContactHappyPath").getClass();test.setTestClasses(new Class[] { cls });通过:
test.setTestClasses(new Class[] { AddContactHappyPath.class });所有代码是
import org.testng.TestNG;import com.xxx.test.others.AddContactHappyPath;public class SampCls { public static void main(String[] args) throws ClassNotFoundException { TestNG test = new TestNG(); test.setTestClasses(new Class[] { AddContactHappyPath.class }); test.run(); }}TestNG代码是:
import org.testng.annotations.*;public class AddContactHappyPath { @Test() public void AddContactHappyPathTest() { System.out.println("hello world"); }}控制台结果:
[TestNG] Running: Command line suitehello world===============================================Command line suiteTotal tests run: 1, Failures: 0, Skips: 0===============================================



