Test Automation for the REST API
With the REST architecture taking over the old MVC patterns, most API started using just one way to communicate with HTTP. Suddenly the business logic and any kind of data processing was done at the server and the client side was only responsible for representation of data and basic manipulations.
Testing of the REST API layer can be done using the REST-assured library that was developed by jay-way company. RESTful APIs generally are of two types: one returning XML responses and one returning JSON response. The assured - lib supports POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD requests and can be used to validate and verify the response of these requests.
You can add a flavor of BDD by using tools like cucumber or specflow:
Testing of the REST API layer can be done using the REST-assured library that was developed by jay-way company. RESTful APIs generally are of two types: one returning XML responses and one returning JSON response. The assured - lib supports POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD requests and can be used to validate and verify the response of these requests.
- Rest-Assured and its dependencies (https://code.google.com/p/rest-assured/wiki/Downloads)
- POM dependencies for the Rest Assured and its dependencies:
When /^I send a GET request for "([^\"]*)"$/ do |path|
get path
end
When /^I send a POST request to "([^\"]*)" with the following:$/ do |path, body|
post path, body
end
When /^I send a PUT request to "([^\"]*)" with the following:$/ do |path, body|
put path, body
end
When /^I send a DELETE request to "([^\"]*)"$/ do |path|
delete path
end
Then /^the response should be "([^\"]*)"$/ do |status|
last_response.status.should == status.to_i
end
Then /^the response JSON should be:$/ do |body|
JSON.parse(last_response.body).should == JSON.parse(body)
end
Further links that might help: http://www.anthonyeden.com/2010/11/testing-rest-apis-with-cucumber-and-rack-test/ http://jeffkreeftmeijer.com/2011/the-pain-of-json-api-testing/ http://www.cheezyworld.com/2011/08/09/running-your-cukes-in-jenkins/
This course gives a good outline of what you might want to look at while creating your framework:
https://www.udemy.com/automation-testing-rest-services/
Also have a look at:
Test Automation for the REST API Thanlku for sharing about this...
ReplyDeleteBest SEO training in hyderabad,training by professional experts during experience more than 15 years,and Giving placement in their company.And giving knowledge of All digital marketing modules with professional practise.Train by expert and Earn huge money per month.Best SEO training in hyderabad
Thanks for the info! Can you please suggest tools for API testing automation?
ReplyDeleteREST API is a set of functions helping developers in performing requests along with receiving responses. Through HTTP protocol interaction is made in REST API.
ReplyDeleteThe term REST refers to Representational State Transfer. In very short span of time, it has become an effective standard for API creation.
Thanks for sharing such a valuable post and Keep Sharing !!!!
Error Free API testing