From the course: Java: Automated API Testing with REST Assured

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Verifying fields of response

Verifying fields of response - Java Tutorial

From the course: Java: Automated API Testing with REST Assured

Start my 1-month free trial

Verifying fields of response

- Given this response body from our request to get the product with ID2. Let's now write assertions for each of the fields of the body. As you can see on line 25 we are already using the assert that method from REST Assured to verify the status code on line 26. We can chain additional assertions to this call. For example, I can say .body and specify any of the fields from the body and verify their values. So as we can see here the first field is ID. So I would place ID here within quotes and then I need to specify a matcher to match the value. Let's talk a little bit more about matchers. The REST Assured library contains Hamcrest matchers. This is a class of functions that allow you to compare your expected result with the actual one. And as you can see there are many different matcher methods that you can choose from. The one you choose depends on what you need to verify and how strictly you'd like to verify it. For…

Contents