亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java調用main自動執行testng方法一

發布時間:2020-06-24 02:52:37 來源:網絡 閱讀:1176 作者:知止內明 欄目:編程語言

主方法


import com.com.utlis.createTestngXml;
import org.testng.TestNG;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lw
 * @createTime 2019/3/30 15:35
 * @description testng調試類
 */
public class inittet {
    private static final String ESCAPE_PROPERTY = "org.uncommons.reportng.escape-output";

    public static void main(String[] args) {
        try {
                //執行的類
            createTestngXml.createTestngXml("com.com.javatest.one.domese");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.setProperty(ESCAPE_PROPERTY, "false");
        List<String> suites = new ArrayList<String>();
        System.out.println(suites);
        suites.add(System.getProperty("user.dir") + "/mytestng.xml");
        TestNG tng = new TestNG();
        tng.setTestSuites(suites);
        tng.run();
    }
}

創建xml方法


import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lw
 * @createTime 2019/3/30 16:12
 * @description 自動生成tesgng.xml
 */
public class createTestngXml {

    public static void createTestngXml(String classname) throws Exception {
        Document document = DocumentHelper.createDocument();
        Element root = DocumentHelper.createElement("suite");
        document.setRootElement(root);
        root.addAttribute("name", "automation");
        root.addAttribute("parallel", "Automatically generate xml");
        root.addAttribute("thread-count", String.valueOf("1"));
        Element listeners = root.addElement("listeners");  //子標簽
        Element listener1 = listeners.addElement("listener");
        listener1.addAttribute("class-name", "org.uncommons.reportng.HTMLReporter");
        Element listener2 = listeners.addElement("listener");
        listener2.addAttribute("class-name", "org.uncommons.reportng.JUnitXMLReporter");
        Element test = root.addElement("test");
        test.addAttribute("name", "127.0.0.1");
        Element classes = test.addElement("classes");
        Element classNode = classes.addElement("class");
        classNode.addAttribute("name", classname);
        OutputFormat format = new OutputFormat("    ", true);
        XMLWriter xmlWrite2;
        try {
            xmlWrite2 = new XMLWriter(new FileOutputStream("mytestng.xml"), format);
            xmlWrite2.write(document);
        } catch (
                UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (
                FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (
                IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("執行成功!!!");
    }
        }

自定義xml

<?xml version="1.0" encoding="UTF-8"?>

<suite name="automation" parallel="Automatically generate xml" thread-count="1">
    <listeners>
        <listener class-name="org.uncommons.reportng.HTMLReporter"/>
        <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
    </listeners>
    <test name="127.0.0.1">
        <classes>
            <class name="com.com.javatest.one.domese"/>
        </classes>
    </test>
</suite>

測試@test

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import org.testng.annotations.Test;
import java.net.http.HttpResponse;

/**

  • @author lw
  • @createTime 2019/3/30 16:12
  • @description 自動生成tesgng.xml
    */

public class domese {
    @Test
    public void ss11() {
        try {
            var url = new URL("http://www.oracle.com/");
            var conn = url.openConnection();
            var reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            System.out.println(reader);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

         @Test
    public void we() {
        String uri = "http://www.baidu.com";

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(uri))
                .GET()
                .build();

        HttpResponse<String> response = null;
        try {
            response = client.send(request, HttpResponse.BodyHandlers.ofString());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(response.body());
    }
        }

結果:

java調用main自動執行testng方法一

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

海南省| 宾川县| 公主岭市| 吐鲁番市| 宁陵县| 红安县| 兴隆县| 迭部县| 额尔古纳市| 西乡县| 邻水| 兴国县| 东阿县| 榆树市| 孙吴县| 锡林郭勒盟| 宜城市| 文水县| 太谷县| 临潭县| 荆门市| 苏尼特左旗| 英德市| 巴青县| 荔浦县| 吉安市| 周宁县| 七台河市| 石屏县| 桑植县| 伊宁市| 襄汾县| 黄梅县| 旌德县| 山丹县| 普洱| 襄汾县| 辽源市| 田东县| 灌南县| 和田市|