接口测试框架开发(一):rest-Assured_接口返回数据验证
2018-02-11 16:04
615 查看
转载:http://www.cnblogs.com/lin-123/p/7111034.html
返回的json数据:{"code":"200","message":"成功","content":{"orgiData":[{"customerName":"十堰市商汇小额贷款股份有限公司","customerId":211}],"queryType":2,"count":1,"resultCode":1}}验证代码:
resp1.body("message", containsString("成功"));
resp1.body("content.resultCode", equalTo(1));
resp1.body("content.orgiData[0].customerId", equalTo(211));
详细代码:
package restAussuredGroup.restAussuredArtifact;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
import io.restassured.response.ValidatableResponse;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class NewPost {
@Test
public void f() {
ValidatableResponse resp1 = given()
.contentType("application/json")
.when()
.post("?jsonStr=eyJ0eXBlIjoiMiIsIm5hbWUiOiLljYHloLDluILllYbmsYflsI/pop3otLfmrL7ogqHku73mnInpmZDlhazlj7giLCJwYWdlU2l6ZSI6IjIwIiwicGFnZU51bSI6IjEifQ==&salt=10f6c0f77a3e34883307646822cb4c31")
.then();
resp1.assertThat().statusCode(200);
System.out.println(resp1.extract().asString());
resp1.body("message", containsString("成功"));
resp1.body("content.resultCode", equalTo(1));
resp1.body("content.orgiData[0].customerId", equalTo(211));
}
@BeforeTest
public void beforeTest() {
RestAssured.baseURI = "http://192.168.103.2";
RestAssured.port = 8580;
RestAssured.basePath = "/cd/rest/ybgcAppOrder/getOrg";
RestAssured.registerParser("text/plain", Parser.JSON);
}
@AfterTest
public void afterTest() {
}
}
相关文章推荐
- 接口测试框架开发(三):maven+restAssured+Excel(jxl)+testng+extentreports的接口自动化
- rest-Assured_接口返回数据验证
- 以Python为基础的REST(JSON为交换数据)接口的测试框架设计(三)-JSON的修改的难点
- 以Python为基础的REST(JSON为交换数据)接口的测试框架设计(一)
- 以Python为基础的REST(JSON为交换数据)接口的测试框架设计(二)-JSON的修改
- 基于python的REST框架eve测试与mongodb的数据操作
- python 接口测试response返回数据对比的方法
- 接口测试框架开发(二):extentreports报告中文乱码问题
- 前端模拟POST发送数据-Chrome下的REST Client(接口测试利器)
- 基于python的REST框架eve测试与mongodb的数据操作 推荐
- java rest接口返回不完整的json数据
- .NET MVC结构框架下的微信扫码支付模式二 API接口开发测试
- python 接口测试response返回数据对比
- 基于maven+restAssured+Excel(jxl)+testng+extentreports的接口自动化-testng上Excel数据读取(一)
- 使用SpingMVC开发rest接口,返回json到页面时,IE提示下载json对话框
- SpringMVC开发移动端接口(返回Json数据)
- 通过Fiddler肆意修改接口返回数据进行测试
- CCS+C6678LE开发记录09:以太网接口测试续(大块数据传输)
- 自己写的粗糙的Excel数据驱动Http接口测试框架(一)
- iOS开发中请求服务器接口返回数据乱码