Run TestNG Suite In Java Main_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Run TestNG Suite In Java Main

Run TestNG Suite In Java Main

 2017/8/8 21:31:20  冰糖葫芦有点酸  程序员俱乐部  我要评论(0)
  • 摘要:Hereisasimpledemoabouthowtoruntestsuitewithjavaprogram:packagecom.test.main;importorg.testng.TestListenerAdapter;importorg.testng.TestNG;importjava.util.ArrayList;importjava.util.List;publicclassTestRunner{publicstaticvoidmain(String[]args){System
  • 标签:Java
Here is a simple demo about how to run test suite with java program:

class="java">
package com.test.main;

import org.testng.TestListenerAdapter;
import org.testng.TestNG;

import java.util.ArrayList;
import java.util.List;

public class TestRunner {
    public static void main(String[] args) {
        System.out.println("Running tests!");

        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG runner = new TestNG();
        // Create a list of String
        List<String> suiteFiles=new ArrayList<>();
        // Add xml file which you have to execute
        //suiteFiles.add(args[0]);
        suiteFiles.add("C:\\test\\testsuite.xml");
        // now set xml file for execution
        runner.setTestSuites(suiteFiles);
        runner.addListener(tla);
        runner.run();
        System.exit(0);
    }
}

Here we can go ahead to run this main method.

Also, if we want to run a TestNG test with a jar, then we can export the program as a jar with Eclipse. Here is the refer to export runnable jar with Eclipse:
http://blog.csdn.net/xiaoguaihai/article/details/42462761

If we want the test suite files as a param in java -jar command, then can modify the program as below:
suiteFiles.add(args[0]);

Run java command in CMD:
java -jar TestRunner.jar C:\\test\\testsuite.xml

Note: You'd better export the jar file in the same folder with source code to avoid there may be some depends for the test running cannnot be found out.
上一篇: 摩根大通全球策略师的警告:技术泡沫随时可能破裂 下一篇: 没有下一篇了!
发表评论
用户名: 匿名