Reputation: 185
I am writing test suite for Rest APIs using cucumber-java. I was trying to use @Rule, however I found it was not supported by cucumber-jvm. Is there any option to write a rule on step failure ?
I am need to print the request-response on assertion failure (I'm asserting on the http response status), so that I can get an understanding on what went wrong?
Any help on this is much appreciated
Upvotes: 1
Views: 322
Reputation: 2819
Cucumber-jvm has the @After annotation and you could put something in there but why not simply include the response in the assertion statement failure text?
I use rest-assured to manage my HTTP request-responses. My responses end up in objects of class Response. To get the entire response, I might code this:
response.getBody().prettyPrint()
EDIT
You specified request as well. Given requestSpec is the instance of class RequestSpecification that we initialized with the request values, I use
requestSpec.given().log().all()
to get the request into string form.
So using JUnit assertTrue
assertTrue("REST service x Status Code =" + response.getStatusCode() +
", for request = " + requestSpec.given().log().all() + ",\n response = " +
response.getBody().prettyPrint(), response.getStatusCode() == 200);
Upvotes: 1