在pom.xml中添加代码:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <!-- 此处指定main方法入口的class --> <mainClass>com.XXX.api.app.App</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </execution> </executions> </plugin>
在main方法执行testng的方法实现:
import org.testng.TestNG; import java.util.ArrayList; import java.util.List; public class App { public static void main(String[] args){ TestNG testNG = new TestNG(); List<String> suites = new ArrayList<String>(); suites.add(".//testng.xml"); testNG.setTestSuites(suites); testNG.run(); } }