<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      基于Java+TestNG+Allure實現(xiàn)接口測試框架的自動化報告

      做一個簡單的基于Java+TestNG+Allure的自動化報告demo

       

      1 環(huán)境準備

      • JDK 1.8+
      • Maven 3.6+
      • IntelliJ IDEA(推薦)

      2 項目結(jié)構(gòu)

      src
      ├── main
      │   └── java
      │       └── com
      │           └── example
      │               └── utils
      │                   └── HttpUtil.java
      └── test
          ├── java
          │   └── com
          │       └── example
          │           └── tests
          │               └── ApiTest.java
          └── resources
              ├── testng.xml
              └── allure.properties
      

      3 添加依賴(pom.xml)

      <dependencies>
          <!-- TestNG -->
          <dependency>
              <groupId>org.testng</groupId>
              <artifactId>testng</artifactId>
              <version>7.4.0</version>
          </dependency>
          
          <!-- Allure -->
          <dependency>
              <groupId>io.qameta.allure</groupId>
              <artifactId>allure-testng</artifactId>
              <version>2.13.8</version>
          </dependency>
          
          <!-- HTTP Client -->
          <dependency>
              <groupId>org.apache.httpcomponents</groupId>
              <artifactId>httpclient</artifactId>
              <version>4.5.13</version>
          </dependency>
          
          <!-- JSON處理 -->
          <dependency>
              <groupId>com.google.code.gson</groupId>
              <artifactId>gson</artifactId>
              <version>2.8.8</version>
          </dependency>
      </dependencies>
      
      <build>
          <plugins>
              <!-- Maven編譯插件 -->
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.8.1</version>
                  <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                  </configuration>
              </plugin>
              
              <!-- TestNG執(zhí)行插件 -->
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>3.0.0-M5</version>
                  <configuration>
                      <suiteXmlFiles>
                          <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                      </suiteXmlFiles>
                      <argLine>
                          -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.7/aspectjweaver-1.9.7.jar"
                      </argLine>
                  </configuration>
                  <dependencies>
                      <dependency>
                          <groupId>org.aspectj</groupId>
                          <artifactId>aspectjweaver</artifactId>
                          <version>1.9.7</version>
                      </dependency>
                  </dependencies>
              </plugin>
              
              <!-- Allure報告插件 -->
              <plugin>
                  <groupId>io.qameta.allure</groupId>
                  <artifactId>allure-maven</artifactId>
                  <version>2.10.0</version>
                  <configuration>
                      <reportVersion>2.13.8</reportVersion>
                  </configuration>
              </plugin>
          </plugins>
      </build>
      

      4 工具類實現(xiàn)(HttpUtil.java)

      package com.example.utils;
      
      import org.apache.http.HttpResponse;
      import org.apache.http.client.methods.HttpGet;
      import org.apache.http.client.methods.HttpPost;
      import org.apache.http.entity.StringEntity;
      import org.apache.http.impl.client.CloseableHttpClient;
      import org.apache.http.impl.client.HttpClients;
      import org.apache.http.util.EntityUtils;
      
      public class HttpUtil {
          public static String doGet(String url) throws Exception {
              try (CloseableHttpClient client = HttpClients.createDefault()) {
                  HttpGet request = new HttpGet(url);
                  HttpResponse response = client.execute(request);
                  return EntityUtils.toString(response.getEntity());
              }
          }
      
          public static String doPost(String url, String jsonBody) throws Exception {
              try (CloseableHttpClient client = HttpClients.createDefault()) {
                  HttpPost request = new HttpPost(url);
                  request.setHeader("Content-Type", "application/json");
                  request.setEntity(new StringEntity(jsonBody));
                  HttpResponse response = client.execute(request);
                  return EntityUtils.toString(response.getEntity());
              }
          }
      }
      

      5 測試用例(ApiTest.java)

      package com.example.tests;
      
      import com.example.utils.HttpUtil;
      import io.qameta.allure.*;
      import org.testng.Assert;
      import org.testng.annotations.Test;
      
      public class ApiTest {
      
          @Test(description = "測試GET請求")
          @Description("驗證GET請求返回狀態(tài)和內(nèi)容")
          @Severity(SeverityLevel.CRITICAL)
          @Story("基礎(chǔ)API測試")
          @Feature("API功能測試")
          public void testGetRequest() throws Exception {
              String url = "https://jsonplaceholder.typicode.com/posts/1";
              String response = HttpUtil.doGet(url);
              
              // 驗證響應包含關(guān)鍵字段
              Assert.assertTrue(response.contains("\"userId\": 1"), "驗證userId");
              Assert.assertTrue(response.contains("\"id\": 1"), "驗證id");
          }
      
          @Test(description = "測試POST請求")
          @Description("驗證POST請求創(chuàng)建資源")
          @Severity(SeverityLevel.NORMAL)
          @Story("數(shù)據(jù)創(chuàng)建測試")
          @Feature("API功能測試")
          public void testPostRequest() throws Exception {
              String url = "https://jsonplaceholder.typicode.com/posts";
              String jsonBody = "{\"title\":\"foo\",\"body\":\"bar\",\"userId\":1}";
              
              String response = HttpUtil.doPost(url, jsonBody);
              
              // 驗證響應包含創(chuàng)建的數(shù)據(jù)
              Assert.assertTrue(response.contains("\"title\": \"foo\""), "驗證title");
              Assert.assertTrue(response.contains("\"id\": 101"), "驗證新資源ID");
          }
      }
      

      6 TestNG 配置文件(testng.xml)

      <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
      <suite name="API_Test_Suite">
          <test name="API_Tests">
              <classes>
                  <class name="com.example.tests.ApiTest"/>
              </classes>
          </test>
      </suite>
      

      7 Allure配置文件(allure.properties)

      allure.results.directory=target/allure-results
      allure.link.issue.pattern=https://example.com/issue/{}
      allure.link.tms.pattern=https://example.com/tms/{}
      

      8 配置實現(xiàn)(關(guān)鍵點):maven的settings.xml文件

      文件路徑

      ${user.home}/.m2/settings.xml(例如:C:\Users\你的用戶名.m2\settings.xml)

      具體配置

      <?xml version="1.0" encoding="UTF-8"?>
      <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 
                http://maven.apache.org/xsd/settings-1.0.0.xsd">
        
        <!-- 本地倉庫位置 -->
        <localRepository>${user.home}/.m2/repository</localRepository>
        
        <!-- 插件組配置(包含Allure插件) -->
        <pluginGroups>
          <pluginGroup>io.qameta.allure</pluginGroup>
        </pluginGroups>
        
        <!-- 代理設(shè)置(根據(jù)實際需要配置) -->
        <!--
        <proxies>
          <proxy>
            <id>optional</id>
            <active>true</active>
            <protocol>http</protocol>
            <username>proxyuser</username>
            <password>proxypass</password>
            <host>proxy.host.net</host>
            <port>80</port>
            <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
          </proxy>
        </proxies>
        -->
        
        <!-- 鏡像設(shè)置(推薦使用阿里云鏡像加速下載) -->
        <mirrors>
          <mirror>
            <id>aliyunmaven</id>
            <mirrorOf>*</mirrorOf>
            <name>阿里云公共倉庫</name>
            <url>https://maven.aliyun.com/repository/public</url>
          </mirror>
        </mirrors>
        
        <!-- 配置文件激活條件 -->
        <profiles>
          <!-- JDK 1.8 配置 -->
          <profile>
            <id>jdk-1.8</id>
            <activation>
              <activeByDefault>true</activeByDefault>
              <jdk>1.8</jdk>
            </activation>
            <properties>
              <maven.compiler.source>1.8</maven.compiler.source>
              <maven.compiler.target>1.8</maven.compiler.target>
              <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
          </profile>
          
          <!-- Allure 配置 -->
          <profile>
            <id>allure</id>
            <properties>
              <allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
            </properties>
          </profile>
        </profiles>
        
        <!-- 激活的配置文件 -->
        <activeProfiles>
          <activeProfile>jdk-1.8</activeProfile>
          <activeProfile>allure</activeProfile>
        </activeProfiles>
      </settings>
      
      

      說明:具體有三點:
      1)本地倉庫位置:

      <localRepository>${user.home}/.m2/repository</localRepository>
      

      2)Allure 插件組配置:

      <pluginGroups>
        <pluginGroup>io.qameta.allure</pluginGroup>
      </pluginGroups>
      

      3)Allure 結(jié)果目錄

      <profile>
        <id>allure</id>
        <properties>
          <allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
        </properties>
      </profile>
      

      9 測試執(zhí)行

      方式一:使用Maven命令

      # 運行測試生成 Allure 結(jié)果數(shù)據(jù)
      # 這會在 target/allure-results 目錄下生成原始結(jié)果數(shù)據(jù)
      mvn clean test
      
      # 生成Allure報告(HTML 格式)
      mvn allure:serve
      

      方式二:使用TestNG直接運行

      1.右鍵點擊testng.xml -> Run
      會在target/allure-results/下生成測試結(jié)果的 .json 文件

      2.生成allure報告

      # 生成Allure報告
      mvn allure:serve
      

      會自動打開測試報告的html地址: http://192.168.82.224:49195/

      10 報告效果

      image
      image

      說明:
      Allure報告將包含:

      • 測試套件概覽
      • 用例詳細步驟
      • 請求/響應詳情
      • 嚴重級別標記
      • 歷史趨勢分析
      • 環(huán)境信息
      posted @ 2025-07-14 18:41  hqq的進階日記  閱讀(104)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 无遮挡aaaaa大片免费看| 成人国产亚洲精品一区二区| 久久国产精品精品国产色婷婷| 男人av无码天堂| 隔壁老王国产在线精品| 中文字幕av无码一区二区三区| 一区二区三区国产不卡| 国产办公室秘书无码精品99| 国产在线乱子伦一区二区| 在线a亚洲老鸭窝天堂| 亚洲中文精品久久久久久不卡| 国产精品一区中文字幕| 国产一区在线播放av| 免费 黄 色 人成 视频 在 线| 国内精品一区二区不卡| 狠狠色婷婷久久综合频道日韩| 激情五月开心婷婷深爱| 亚洲人成网站18禁止无码| 亚洲av色香蕉一区二区| 中文字幕无码av不卡一区| 国产主播精品福利午夜二区| 午夜家庭影院| 国产一区二区三区18禁| 不卡乱辈伦在线看中文字幕| 久久精品女人的天堂av| 日韩av日韩av在线| 国产成人精品无码播放| 一卡2卡三卡4卡免费网站| 88国产精品视频一区二区三区| 潮喷无码正在播放| 亚洲红杏AV无码专区首页| 亚洲精品一区国产精品| 中文字幕精品亚洲无线码二区| 亚洲人妻精品一区二区| 国产精品国产高清国产av| 国产普通话对白刺激| 国产精品二区中文字幕 | 国精产品一品二品国精在线观看| 亚洲性一交一乱一伦视频| 亚洲日韩图片专区第1页| 综合久青草视频在线观看|