I want to add a condition to Rest Assured. For example, if I have input 1, the request should be checked for condition 1, but if I do not have input 1, condition 1 should not be checked. Of course I could do the if outside the request and just not add the check, but I have several cases like this this is a lot of unnecessary code. Is there any way I can save code using an inline if?
if (condition1){
response =
given().
spec(spec).
body(data).
when().
post("/test").
then().
assertThat().
statusCode(201).
body("id", 1).
extract().
response();
} else {
response =
given().
spec(spec).
body(data).
when().
post("/test").
then().
assertThat().
statusCode(201).
//DONT DO THE CHECK
extract().
response();
}
Is there a way to do that in one line? Something like this:
response =
given().
spec(spec).
body(data).
when().
post("/test").
then().
assertThat().
statusCode(201).
if condition do this body("id", 1) otherwise dont do anything
extract().
response();
Aucun commentaire:
Enregistrer un commentaire