- Application
- Programming
- Interface
- Request
. Endpoint
. Headers
. Body - Response
. Status Code
. Headers
. Body
- Parameterization and data driven testing
- Verifying response headers and bodies
- Optimizing your test code through reuse
- (De-) serializing request and response bodies
- Java DSL for writing tests for RESTful APIs
- Runs on top of JUnit or TestNG
- Supports all HTTP methods (GET, POST, PUT, DELETE, ...)
- Supports Gherkin syntax (Given/When/Then)
- Uses Hamcres matchers for checks
- Uses JsonPath/Gpath and XmlPath for selecting elements from response
- Developed and maintained by Johan Haleby
- Source: https://rest-assured.io/
Configuring REST Assured
- Maven
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
- TestNG
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
Website: https://www.zippopotam.us/
- Supplies location data related to given country and zip code
- An example request and response
Structure: api.zippopotam.us/country/postal-code
api.zippopotam.us/us/90210
- JSON Result
{
"post code": "90210",
"country": "United States",
"country abbreviation": "US",
"places": [
{
"place name": "Beverly Hills",
"longitude": "-118.4065",
"state": "California",
"state abbreviation": "CA",
"latitude": "34.0901"
}
]
}
- Step 1: Create a test data collection
- Step 2: Feed data collection to your test method
- Step 3: Use path parameters to parameterize REST Assured tests
- Step 4: Update the specified test data
1- Reusable request specifications
2- Reusable response checks
3- Extracting response values for reuse