[英]How to add testng parameters in a java main method?
I wanted to trigger the execution from a java main method instead of testng.xml file.我想从 java main 方法而不是 testng.xml 文件触发执行。
My doubt is how to add the parameters to Java main method for the execution.我的疑问是如何将参数添加到 Java main 方法中以供执行。 I have found .addListener and .setGroups to add listener and groups respectively, but couldn't able to find a way to add parameters.
我已经找到 .addListener 和 .setGroups 分别添加侦听器和组,但无法找到添加参数的方法。
Please help me out to start the exection through java main method.请帮助我通过 java main 方法开始执行。
Sample:样本:
public class Execution {
public static void main(String[] args) throws IOException {
TestNG test = new TestNG();
test.setTestClasses(new Class[] {AETVTests.class});
test.addListener(new MyTestListenerAdapter());
test.setGroups("");
test.run();
}
}
If you would reconsider using xml - you can also trigger execution through the main method with the xml file.如果您重新考虑使用 xml - 您还可以通过带有 xml 文件的 main 方法触发执行。 Add the testng.xml file to your project path (in eclipse you can right click project - new - file - testng.xml), and this will work:
将 testng.xml 文件添加到您的项目路径(在 Eclipse 中您可以右键单击项目 - 新建 - 文件 - testng.xml),这将起作用:
public static void main(String[] args) throws IOException
{
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("C:\\eclipse-2018\\Tests\\testng.xml"); //path to xml
testng.setTestSuites(suites);
testng.run(); //run TestNG
}
You can access args by arg[0],arg[1] likewise.您也可以通过 arg[0],arg[1] 访问 args。 in cmd run your jar file> java -jar classname.jar param1 param2
在 cmd 中运行你的 jar 文件> java -jar classname.jar param1 param2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.