本文转自测试人社区,原文链接: https://ceshiren.com/t/topic/28386
接口测试场景
title 功能测试与接口测试对比
scale 2
actor 测试工程师 as tester
participant 前端页面 as fronted
participant 后端服务 as backend
group 功能测试
tester -> fronted: 测试工程师在系统页面做点击输入等操作
fronted-> backend: 通过接口发起请求信息
backend -> fronted: 返回响应,前端渲染页面
fronted -> tester: 通过页面查看对比响应内容与预期是否一致
end
group 接口测试
tester -> backend: 通过接口发起请求信息
backend -> tester: 返回响应,对比响应内容与预期是否一致
end
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
自动化测试场景
title UI自动化测试与接口自动化测试对比
scale 2
actor 测试工程师 as tester
participant 代码 as code
participant 前端页面 as fronted
participant 后端服务 as backend
group UI自动化测试
tester → code: 测试工程师编写【UI自动化测试】脚本
code → fronted: 脚本在页面上模拟点击、输入等操作
fronted-> backend: 通过接口发起请求信息
backend → fronted: 返回响应,前端渲染页面
fronted → code: 通过页面查看对比响应内容与预期是否一致
end
group 接口自动化测试
tester → code: 测试工程师编写【接口自动化】测试脚本
code → backend: 通过接口发起请求信息
backend → code: 返回响应,对比响应内容与预期是否一致
end
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
接口测试在分层测试中的位置
接口自动化测试与 Web/App 自动化测试对比
接口自动化测试与 Web/App 自动化测试对比
看起来接口自动化测试什么都比 Web/App 自动化测试要好,为什么还要做 Web/App 自动化测试?
- 接口关注数据无法触达用户体验。
接口自动化测试场景
接口自动化测试在企业中的实践
接口测试的市场需求
接口测试工具类型
为什么推荐 REST-assured
- 是由 Java 实现的 REST API 测试框架。
- 支持发起 POST, GET, PUT, DELETE 等请求。
- 可以用来验证和校对响应信息。
REST-assured 优势
- 支持多种数据格式:支持
xml/json
的结构化解析。 - 内置断言库:支持
xpath/jsonpath/gpath
解析方式。 - 可与多种测试框架集成:支持与 JUnit、TestNG 等测试框架集成。
REST-assured 环境准备
- 创建 maven 项目。
- 基于 JDK 11、JUnit5。
- pom.xml 添加 rest-assured 的依赖。
附录:完整依赖配置
<!-- 其他使用到的依赖配置 -->
<!-- 版本配置-->
<properties>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<java.version>11</java.version>
<junit.jupiter.version>5.9.2</junit.jupiter.version>
<maven.compiler.version>3.11.0</maven.compiler.version>
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>
<rest-assured.version>5.3.0</rest-assured.version>
<json-path.version>2.8.0</json-path.version>
<!-- allure报告 -->
<allure.version>2.21.0</allure.version>
<aspectj.version>1.9.19</aspectj.version>
<allure.maven.version>2.12.0</allure.maven.version>
<allure.cmd.download.url>
https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline
</allure.cmd.download.url>
</properties>
<dependencyManagement>
<!-- junit5 版本管理, 找到对应依赖关系的 pom 文件,为了解决依赖冲突问题-->
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- junit 相关依赖下载-->
<!-- junit5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- junit5-suite -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<!-- 用做兼容老版本 -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<!-- rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>compile</scope>
</dependency>
<!-- json path 解析json文件 -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${json-path.version}</version>
</dependency>
<!-- allure报告-->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- maven 命令行执行插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<!-- 防止maven与junit5使用依赖冲突的问题-->
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- maven 编译使用插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<parameters>true</parameters>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${maven.compiler.encoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>${allure.maven.version}</version>
<configuration>
<reportVersion>${allure.version}</reportVersion>
<allureDownloadUrl>${allure.cmd.download.url}/${allure.version}/allure-commandline-${allure.version}.zip</allureDownloadUrl>
</configuration>
</plugin>
</plugins>
</build>
package com.restassured;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
public class FirstTest {
@Test
public void demo(){
when().
get("https://ceshiren.com/").
then().
statusCode(200);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.