Reputation: 725
I have a rest assured test where I am converting the json into the java object and asserting on the java object.In the response object there is a particular value that I am asserting on in the test. When I run the service manually using POSTMAN I always see the parameter value in the response but when my automation tests execute the value is not always present in the response object.
I am suspecting it can be the issue from the service side not sending the consistent response but when hit manually the value is always present.
Test code:
@Test
public void validateResponse() {
RequestObject.name= "Hello";
RequestObject.age="20";
ResponseObject responseObject= given()
.contentType(TestData.CONTENT_TYPE_FOR_TEST)
.body(RequestObject)
.then()
.log()
.everything()
.when()
.post(uri)
.as(ResponseObject.class);
assertNotNull(responseObject.name);
assertNotNull(responseObject.year.age);
I think my test is simple not complicated but the assertion fails intermittently.
Any insight of how to debug more on this?
Upvotes: 0
Views: 513
Reputation: 40510
Your fields in RequestObject
looks static and I think it's quite likely the JSON object mapper won't bind the result to static fields. Try make them non-static.
Upvotes: 1