SpringBoot 微服务接口自动化测试两套完整实战工程_第1页
SpringBoot 微服务接口自动化测试两套完整实战工程_第2页
SpringBoot 微服务接口自动化测试两套完整实战工程_第3页
SpringBoot 微服务接口自动化测试两套完整实战工程_第4页
SpringBoot 微服务接口自动化测试两套完整实战工程_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论