软件测试学习笔记丨接口自动化测试框架介绍
作者:测试人
- 2024-07-15 北京
本文字数:3698 字
阅读完需:约 12 分钟
本文转自测试人社区,原文链接:https://ceshiren.com/t/topic/28386
接口测试场景
title 功能测试与接口测试对比scale 2actor 测试工程师 as testerparticipant 前端页面 as frontedparticipant 后端服务 as backend
group 功能测试tester -> fronted: 测试工程师在系统页面做点击输入等操作fronted-> backend: 通过接口发起请求信息backend -> fronted: 返回响应,前端渲染页面fronted -> tester: 通过页面查看对比响应内容与预期是否一致endgroup 接口测试tester -> backend: 通过接口发起请求信息backend -> tester: 返回响应,对比响应内容与预期是否一致end复制代码
自动化测试场景
title UI自动化测试与接口自动化测试对比scale 2actor 测试工程师 as testerparticipant 代码 as codeparticipant 前端页面 as frontedparticipant 后端服务 as backendgroup UI自动化测试tester → code: 测试工程师编写【UI自动化测试】脚本code → fronted: 脚本在页面上模拟点击、输入等操作fronted-> backend: 通过接口发起请求信息backend → fronted: 返回响应,前端渲染页面fronted → code: 通过页面查看对比响应内容与预期是否一致endgroup 接口自动化测试tester → code: 测试工程师编写【接口自动化】测试脚本code → backend: 通过接口发起请求信息backend → code: 返回响应,对比响应内容与预期是否一致end复制代码
接口测试在分层测试中的位置
接口自动化测试与 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 的依赖。
<!-- rest-assured 相关依赖 --><properties> <rest-assured.version>5.3.0</rest-assured.version></properties><dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>${rest-assured.version}</version></dependency>复制代码
附录:完整依赖配置
<!-- 其他使用到的依赖配置 --><!-- 版本配置--><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); }}复制代码
软件测试开发免费视频教程分享
划线
评论
复制
发布于: 刚刚阅读数: 4
版权声明: 本文为 InfoQ 作者【测试人】的原创文章。
原文链接:【http://xie.infoq.cn/article/c8f446de7be2694c4e5e261e6】。文章转载请联系作者。
测试人
关注
专注于软件测试开发 2022-08-29 加入
霍格沃兹测试开发学社,测试人社区:https://ceshiren.com/t/topic/22284







评论