Sunday, October 16, 2016

Sample REST-assured Project for REST API testing

We decided to experiment  building a simple REST API testing framework in a Java Maven project using REST-assured and testNG. There are several blogs that explain how to use it but we could not find a sample framework to use as a base. Therefore, we decided to build one from scratch and make it available for others to use. The project can be found in github at this location: https://github.com/mtristain/restapitestsample

Building a REST-assured test framework from scratch was surprisingly easy to do. Especially if you are using Maven or Gradle. The instructions on how to install and run the tests are also in the same location above. In order to add tests to our sample REST API testing framework, we needed some publicly available Restful APIs. The REST APIs for testing and prototyping at JSON Placeholder did the trick. The base class is very simple as you can see below. It obviously needs more work if you are planning on using it for more sophisticated APIs.


There are a total of 20 tests at the time of this post. The tests are simply validating response codes, certain content, or the size of the response object.

Sample #1: Validate status code




 Sample #2: Validate response size:


 Sample #3: Validate that 100th item contains certain content.



After automating these tests we decided to schedule a run in Jenkins and load the results to TestRecon. We used a PowerShell script to call the Recon APIs and load the results after the tests completed. The results can be seen below. You can also generate these reports and slice and dice your test results using TestRecon.








Stay tuned to find out the steps and instructions on how to use PowerShell to make http calls and load test results to TestRecon or other tools.


Set up your free account at testrecon.com