background
Use TestNG to write the test cases, through the @test to execute the use case, the general local through the IDE to execute the corresponding method, continuous integration, all through Maven to execute or specify Testng.xml execution, but if you want to execute the test case through interface/interface.
Steps
TestNG actually provides two ways to do this through code.
1. Execute by class, show the code:
TestNG TestNG = new TestNG ();
Testng.settestclasses (new class[] {webtestfactory.class});
Testng.run ();
Create a new TestNG object, Settestclass Pass in the class of a use case, then execute the use case run ();
2. Execute via suite, show the code:
Xmlsuite Suite = new Xmlsuite ();
Suite.setname ("Tmpsuite");
XmlTest test = new XmlTest (suite);
Test.setname ("Tmptest");
list<xmlclass> classes = new arraylist<xmlclass> ();
Classes.add (New Xmlclass ("Test.failures.Child"));
Test.setxmlclasses (classes);
list<xmlsuite> suites = new arraylist<xmlsuite> ();
Suites.add (suite);
TestNG TNG = new TestNG ();
Tng.setxmlsuites (suites);
Tng.run ();
Notes
If you want to invoke the specified method directly, you need to toss the next
Todo