Set restAssured to log all requests and responses

2019-04-22 02:49发布

I want to enable logging for all restAssured responses and requests by default.

Here's what I do:

RestAssured.requestSpecification = new RequestSpecBuilder().
        setBaseUri("api").
        setContentType(ContentType.JSON).
        build().
        log().all();
RestAssured.responseSpecification = new ResponseSpecBuilder().
        build().
        log().all();

requestSpecification works alright, but with responseSpecification I get:

Cannot configure logging since request specification is not defined. You may be misusing the API.

I really don't want to use log().all() after each then.

2条回答
Evening l夕情丶
2楼-- · 2019-04-22 03:39

I think you need to see the logs then test fails, in this case just use this configuration from rest assured:

RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

查看更多
相关推荐>>
3楼-- · 2019-04-22 03:46

Add logging filters to defaults of RestAssured, see here.

查看更多
登录 后发表回答