REST Assured

    xiaoxiao2021-11-11  96

    1、配置

    RestAssured.baseURI = "http://...." RestAssured.port = 8800 RestAssuredConfig RAconfig = new RestAssuredConfig(); //设置UTF-8编码 RestAssured.config = RAconfig.encoderConfig(new EncoderConfig("UTF-8", "UTF-8"));

    2、POST

    //map以参数名-参数值的形式 MAP map = new HashMap<String, String>(); RestAssured.given().params(map).when().post("/");

    3、ASSERT

    body的返回模型校验

    Response resp = RestAssured.given().params(map).when().post("/"); //jsonSchema String jsonSchema = ""; resp.then().assertThat().body(JsonSchemaValidator.matchesJsonSchema(jsonSchema));

    body的字段检验(检验需要区分字段类型)

    resp.then().assertThat().body("jsonPath",equalTo("hello"); resp.then().assertThat().body("jsonPath",equalTo(1);

    4、反序列化

    Response resp = RestAssured.given().params(map).when().post("/"); xx bean = resp.as(xx.class);
    转载请注明原文地址: https://ju.6miu.com/read-678187.html

    最新回复(0)