版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SpringBoot微服务接口自动化测试两套完整实战工程1.Maven依赖pom.xmlxml<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="/POM/4.0.0"><dependencies><!--RestAssuredhttp请求核心--><dependency><groupId>io.rest-assured</groupId><artifactId>rest-assured</artifactId><version>5.3.2</version><scope>test</scope></dependency><!--TestNG测试框架--><dependency><groupId>org.testng</groupId><artifactId>testng</artifactId><version>7.7.1</version><scope>test</scope></dependency><!--Allure报告--><dependency><groupId>io.qameta.allure</groupId><artifactId>allure-testng</artifactId><version>2.24.0</version><scope>test</scope></dependency><!--yaml配置解析--><dependency><groupId>org.yaml</groupId><artifactId>snakeyaml</artifactId><version>2.2</version></dependency><!--lombok--><dependency><groupId>jectlombok</groupId><artifactId>lombok</artifactId><version>1.18.30</version><scope>provided</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.11.0</version><configuration><source>17</source><target>17</target></configuration></plugin><!--allure插件--><plugin><groupId>io.qameta.allure</groupId><artifactId>allure-maven</artifactId><version>2.10.0</version></plugin></plugins></build></project>2.项目结构plaintextiot-api-test-java/src/test/java/com/iot/test├──config│└──EnvConfig.java//多环境配置加载├──common│├──BaseRequest.java//RestAssured封装基类│└──LoginSetup.java//前置登录├──dto//可直接copy后端DTO实体│├──LoginReq.java│└──MetricQueryReq.java├──testcases│├──AuthTest.java│├──ElevatorDeviceTest.java│└──MetricHistoryTest.javasrc/test/resources├──env.yaml└──perties3.环境配置resources/env.yamlyamlenv:testdev:baseUrl::8080test:baseUrl:user:username:adminpassword:1234564.请求封装common/BaseRequest.javajava运行packagemon;importcom.iot.test.config.EnvConfig;importio.restassured.RestAssured;importio.restassured.config.RestAssuredConfig;importio.restassured.config.SSLConfig;importio.restassured.http.ContentType;importio.restassured.response.Response;importio.restassured.specification.RequestSpecification;publicclassBaseRequest{publicstaticStringTOKEN;publicstaticStringBASE_URL=EnvConfig.getBaseUrl();//获取请求specpublicstaticRequestSpecificationgetSpec(){RequestSpecificationspec=RestAssured.given().baseUri(BASE_URL).contentType(ContentType.JSON).config(RestAssuredConfig.config().sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation()));if(TOKEN!=null){spec.header("Authorization","Bearer"+TOKEN);}returnspec;}publicstaticResponsepost(Stringuri,Objectbody){returngetSpec().body(body).post(uri);}publicstaticResponseget(Stringuri){returngetSpec().get(uri);}publicstaticResponseget(Stringuri,Objectparams){returngetSpec().queryParams(params).get(uri);}}5.前置登录类LoginSetup.javajava运行packagemon;importcom.iot.test.dto.LoginReq;importio.restassured.response.Response;importorg.testng.annotations.BeforeSuite;publicclassLoginSetup{@BeforeSuitepublicvoidloginInit(){LoginReqreq=newLoginReq();req.setUsername("admin");req.setPassword("123456");Responseresp=BaseRequest.post("/api/auth/login",req);Stringtoken=resp.path("data.token");BaseRequest.TOKEN=token;}}6.业务用例示例MetricHistoryTest.java(TDengine时序查询接口)java运行packagecom.iot.test.testcases;importmon.BaseRequest;importmon.LoginSetup;importcom.iot.test.dto.MetricQueryReq;importio.qameta.allure.Allure;importio.qameta.allure.Feature;importio.qameta.allure.Story;importio.restassured.response.Response;importorg.testng.Assert;importorg.testng.annotations.Test;@Test(groups="api",suiteName="时序指标接口",dependsOnGroups="login")publicclassMetricHistoryTestextendsLoginSetup{@Test@Feature("时序数据查询模块")@Story("电梯历史指标查询(TDengine)")publicvoidtestQueryElevatorMetric(){Allure.description("查询elev_001一天运行时序数据");MetricQueryReqreq=newMetricQueryReq();req.setDeviceId("elev_001");req.setStartTime("2026-08-0100:00:00");req.setEndTime("2026-08-0200:00:00");Respon
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年吕梁地区汾阳市中小学教师招聘笔试模拟试题及答案详解
- 2026年伊春市西林区街道办人员招聘考试参考题库及答案详解
- 2026年郑州市管城回族区中小学教师招聘考试备考题库及答案详解
- 2025年菏泽市牡丹区中小学教师招聘考试试题及答案详解
- 2026年上海市闵行区中小学教师招聘考试模拟试题及答案详解
- 2026年涪陵区辅警协警招聘笔试参考试题及答案详解
- 2026年广元市元坝区街道办人员招聘笔试参考题库及答案详解
- 2026年南宁市邕宁区中小学教师招聘考试备考题库及答案详解
- 2026年阿克苏地区中小学教师招聘考试备考试题及答案详解
- 2026年北京市丰台区中小学教师招聘考试参考题库及答案详解
- 2026年重庆市“五方面人员”选拔乡镇领导班子考试历年参考题库(含完整答案)
- 家政保姆入户服务标准化礼仪规范
- 2026秋新教科版科学五年级上册教学课件:第四单元 第5课 岩石的类别与变化 有2个微课视频
- 2026年浙江基层法律服务工作者执业核准考试试题及答案
- 2026年幼儿园课程故事培训会
- 2025年全国检察官遴选考试真题及参考答案
- 2026年中国石油辽阳石化分公司校园招聘笔试参考试题及答案解析
- 2026年新水利安全员b证考试试题及答案
- 二年级上册数学【应用题乘法】80题(含答案)
- 2026年全国中考语文试题汇编-议论文阅读及答案
- 冶金安全评价标准考试试题及答案
评论
0/150
提交评论