zoukankan      html  css  js  c++  java
  • 接口测试框架开发(一):rest-Assured_接口返回数据验证

    转载: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() {
    }

    }

  • 相关阅读:
    linux学习方法之一
    HDU 1556 Color the ball
    Object-c学习之路十(NSNumber&NSValue)
    蜂鸣器驱动方式源程序--有源无源通用
    Wordpress更换主题之后出错
    mybatis_Generator配置
    Logistic Regression
    求两个字符串的最大公共字串
    数据结构排序系列详解之二 希尔排序
    《mysql必知必会》学习_第五章
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/8442316.html
Copyright © 2011-2022 走看看