Is there any opportunity to add an assertion message in Rest Assured method?

Viewed 567

Is there any opportunity to add assertion message into my method using libraries of Rest Assured? For example, I want to write an assertion message in this chain method without using System.out.println().

given().spec(requestSpecBuilder).when().get(commentsEndPoint).then().
            spec(responseSpecification).assertThat().contentType(ContentType.JSON.withCharset("UTF-8"))
2 Answers

No, Rest-Assured doesn't have any methods like this.

To add assertion message, you can use Hamcrest directly.

Response res = given().when().get("your_url");
assertThat("Check status code", res.statusCode(), Matchers.is(200));

You can use org.hamcrest.Matchers.describedAs() to add assertion message:

    given().spec(requestSpecBuilder).when().get(commentsEndPoint).then().
            spec(responseSpecification)
            .contentType(describedAs("Error message",
                    equalTo(ContentType.JSON.withCharset("UTF-8"))));
Related