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 - Java Tutorial
From the course: Java: Automated API Testing with REST Assured
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Anatomy of a response2m 1s
-
(Locked)
Verifying status code of a response2m 20s
-
(Locked)
Accessing response body1m 35s
-
(Locked)
Verifying fields of response5m 50s
-
(Locked)
Verifying complex response bodies7m 37s
-
(Locked)
Verifying response header2m 52s
-
(Locked)
Deserializing response body7m 54s
-
(Locked)
Challenge: Verify API response33s
-
(Locked)
Solution: Verify API response1m 55s
-
(Locked)