我们可以逐步构建io.restassured的RequestSpecification吗?

时间:2019-01-10 14:20:43

标签: rest-assured

我正在以以下方式形成io.assertassured请求/响应

    Response response = RestAssured.given().headers("Authorization", "Bearer    token).contentType(ContentType.JSON).body(tempJsonString).post(MY_ENDPOINT). 
    andReturn();

我想逐步创建请求,例如,

    //Authorization
     RequestObject request = RestAssured.given().headers("Authorization", "Bearer"+token);
    //Adding body; tempJsonString is already defined
    request = request.body(tempJsonString);
    //Adding HTTP Verb; MY_ENDPOINT is already defined
    request = request.post(MY_ENDPOINT)
    //Finally
    Response response = request().andReturn();

io.restassured DSL是否可能?

1 个答案:

答案 0 :(得分:0)

您可以使用 io.restassured.builder.RequestSpecBuilder

RequestSpecBuilder requestBuilder = new RequestSpecBuilder();
requestBuilder.setBaseUri("http://www.example.com");
requestBuilder.setBasePath("/path");
requestBuilder.addHeader("Authorization", "Bearer" + token);
RequestSpecification request = RestAssured.given().spec(requestBuilder.build()).when();
Response response = request.post().andReturn();