Rest Assured vs Cucumber - rest

I know what Rest Assured is and for what purpose it is used and the same for the cucumber.
But the thing is what we can achieve with Rest Assured, we can also do with Cucumber for testing.
Rest Assured simply calls the web service and validates the response. We can't use Rest Assured during the Maven build because the service needs to be up and running.
But with Cucumber I can directly call the web service's business service layer and DOA layer and validate the response. Cucumber can invoke this at Maven build time.
So question is which one is better? I know we can use/integrate Cucumber with Rest Assured but.

Cucumber is a BDD tool and can be used to describe the expected behavior and use those descriptions as the basis for test automation.
RestAsured is a tool to test API's/http calls.
They do something different.
You could use them both: Cucumber to describe you functionality, and RestAssured to do http calls.

But with Cucumber i can directly call the web service's business service layer and doa layer and validate the response.
This is not necessarily true, and it has to do with the test level you want to achieve.
So if you just want to do tests on a unit level, then yes, you don't need to use REST assured, you can perfectly specify your tests with Cucumber feature files, and in the step definitions, you can test the service layer and the DOA layer directly, like you mentioned.
If you want to test a running instance of the webservice then you can use REST Assured or REST Assured plus Cucumber. REST Assured will only help you simplify the actual definition of each part of the test and the interactions with endpoints and its expectations, and Cucumber will allow you to define the high-level scenarios made of those steps.
So the question is which one is better? I knew we can use integrate cucumber with rest assured but.
All in all, it's not a matter of which one is better, but what level of testing you're trying to achieve and how you want to achieve it. A unit level you might not need REST assured. On an integration/live-execution level, then yes, you can use that library. In both levels, you can specify your tests using Cucumber.

Rest assured is java Api libraries to do automate REST web services. we can automated Rest apis by using BDD method,BDD is method and Cucumber is leading and free tool for that

Rest assured is not a tool it is a java library which we can use for test restful webservices, and yes cucumber is recommended to use because customer is giving better reporting which rest assured is not supporting to reports.
So I can recommend use cucumber framework to test API

Related

Rest API testing with JGiven

I am quite new to JGiven and currently I have a set of REST API tests automated using Rest Assured and TestNG framework. I am also exploring JGiven as a framework to run the API tests for the advantages it gives with the human readable given when thens and the reports that it generates too. Rest Assured as a library lets us inject the URLs and actually make the REST calls. I want to understand if we have such capabilities within JGiven to actually make the REST calls. If so, I'd like to see an example and understand how I can do that. If not, can someone kindly advice and suggest the best way to achieve it with JGiven. I've been trying to search for this information but have struggled to do so thus far.
Thanks in advance.
JGiven is useful for creating test scenarios that are understandable by domain experts. It is a general tool that can be used for any kind of testing, including testing REST APIs. JGiven adds an understandable layer on top of your underlying test infrastructure. However, you will typically need tools in addition to JGiven to implement the underlying layer. So for testing REST APIs you will use a tool like Rest Assured in combination with JGiven. With JGiven you describe your scenario in the domain language, with Rest Assured you will execute the REST calls.

Best way to implement REST API testing with Nightwatch.js

I'm using Nightwatch-Cucumber that based on Nightwatch.js. And I want to integrate REST API tests in my Nightwatch framework. Currently I only have End2End tests based on Selenium, but in future I want to have both test types in one framework to make it also possible to use the End2End tests and the REST API tests in harmony within one Cucumber test. So, I want to combine both tests.
What is the best and smartest way to implement such REST API tests in my test framework based on Nightwatch-Cucumber? I've tried some stuff with frisby.js, but this framework uses Jasmine and Jest and it's not a good idea to use it in combination with Nightwatch and Cucumber.
Any recommendations?
You can use request-promise.
In nearest future, new version of nightwatch-cucumber will work with Jasmine and Jest too.

RestFuse vs Rest Assured vs MockMVC Rest Service Unit Test Framework

I've been trying to find a simple all purpose unit test framework for Spring MVC based Rest Services I've written.
I've been searching online and narrowed it down to:
RestFuse (http://developer.eclipsesource.com/restfuse/)
Rest Assured (https://github.com/jayway/rest-assured)
MockMVC (http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-rest-api/)
I like RestFuse because it's mostly annotation based, but rest assured seems to have a easier way of passing parameters and checking responses. And finally being a Spring MVC Rest Service project, I'm wondering if I should just stick with the already established way of testing Rest Services in Spring with MockMVC.
Interested to get any feedback, as well as performance, past experiences and if there's anything else I should take into consideration.
Rest-Assured is gaining acceptance over the other frameworks to test REST services in Java. Having BDD style fluent interface, its easy to read the test scripts also, with minimal learning curve.
I am using this framework for verifying REST services as an end user, and it has been easier to implement test scripts for them. Hence I cannot comment much on Spring MVC part of REST-assured.
However, this blog post gives you more details on RestAssured v2.2 which includes spring-mock-mvc module built on top of MockMVC giving BDD style fluent interface flavor through REST assured. The blog post also cautions:
When not to use it:
RestAssuredMockMvc is not to be considered a complete replacement to
vanilla MockMvc since it contains more specific features coupled to
Spring MVC. For example right now there’s no first class support for
things like flash attributes and principals. You can how ever add
those by using an interceptor. Standard REST Assured also supports a
lot of different authentication schemes and filters which are not
available in the RestAssuredMockMvc API. Another reason for why you
may want to use the standard REST Assured API is if it’s important to
your organization to test the REST API in a real container (for
example if you’ve configured authentication or authorization in a
container specific manner) or if you’re using JAX-RS (or any other
framework regardless of language).
Finally, have a look at REST-Assured spring-mvc-webapp examples in REST-assured codebase, and decide, whether you like to give a try for it and make the best use of both REST-assured and MockMVC frameworks.
The beauty of MockMVC is that it provides a mock servlet container, allowing you to integration-test your REST services without deploying to a web server. I believe that you can still leverage this power when using REST Assured with the spring-mock-mvc module.
Another framework that I just learned of is Karate. Its author is currently experimenting with a mechanism to allow execution in a mock servlet container (see Peter Thomas' answer to Is there a mechanism for integration testing JAX-RS services without deploying (a la MockMVC)?).

Automate Rest API test and integrate this with Continuous Integration(CI-Jenkins)

I found many similar questions related to this, but not the particular answer I am looking for. Actually my requirement is little different, so I end up posting the following issue.
I want to automate Rest APIs, and I got two options for the same case.
The first one is Rest Assured and second one is Play Framework.
For example, to test this RestAPI:
http://servername:9000/dbs/all/list/m1/p1/sch1
(↑ This gives xml response)
So, I have written a code in Java with Rest assured, and is working fine. I integrate this with Maven project so that can be integrated with Jenkins.
Sample code:
import com.jayway.restassured
public class TestNGSimpleTest2 {
#Test
public void testApi() {
expect().
statusCode(200).
body("Status", equalTo("Su22ccess")).
when().
get("http://localhost:9000/dbs/all/list/m1/p1/sch1");
}
So my first question is:
Is the rest assured is the best tool to use?
Does Play framework is better?
I found many other tool like Jmeter, RightAPI etc. to test RestAPI. But I dont think this is automable. Am I right?
For automating REST API testing, as a starting point I recommend using Postman and newman.
Postman provides an excellent UI for building requests, and newman is its command-line counterpart. After you create a set of requests and corresponding tests within the Postman UI, you can run the entire collection from Jenkins via newman, preventing a deployment if tests fail.
The RestAssured code you have posted will work just fine for basic cases. It's not necessarily the "right tool" if you want to:
continuously add new test case and don't have many resources
propogate alerts with well-formed error messages (especially to places like Slack or GitHub)
reduce false-positives
re-use the same tests for monitoring
Building these features takes time and resources which, depending on the size of your team may or may not be a good call.
Some of the commercial solutions you posted can solve some of these problems for you.
Assertible is a codeless solution that supports the workflow you described directly: https://assertible.com/blog/automated-api-testing-with-jenkins
We can integrate Jenkins and JMeter for automating RestAPI testing.
The reason for that is,
In Jenkins we can schedule our tests/builds in whichever way(every minute/hour/day/month.....) or based on the commits etc..
we can bundle n number of APIs together in JMeter and execute in a single test.(Maintaining is easy)
There is a jenkins plugin "Performance" which can be used to check the response time for each API call, which compares the response time with respect to the previous response times.
JMeter has an in-build threading feature, which helps execute tests much faster than any single threaded tests.
Screenshots:
Steps
We can prepare our APIs in JMeter
Configure the tests in non GUI Mode in Jenkins.
Install and Configure the Performance plugin in Jenkins.

how to use rest-assured for integration tests on my WS without modyfing database state?

I'm currently developping a REST Web service with Spring MVC.
And I am struggling to find the best way to do integration tests on my WS.
First solution : using rest-assured
Advantage : fluent api, really easy to use with its cool DSL
Drawback : when i perform POST or PUT requests on my WS, the state of my database is modified, and next tests are corrupted.
Second solution : unit test the controllers and perform integration tests at the service level separately
Advantage : i can control the state of my database, using Spring Test Framework and perform rollback after each test
Disadvantage : i do not perform end-to-end integration tests anymore.
Question : how can i use rest-assured to do integration tests without modifying the state of my database ?
Thanks a lot.
Why don't you delete the rest assured doubles and redirects before every test and set them up fresh for the test?
RestClient.delete "#{RestAssured::Server.address}/redirects/all"
RestClient.delete "#{RestAssured::Server.address}/doubles/all"
Or alternatively you can use different doubles for the GET and POST/PUT calls to the rest assured and use the redirects in between these calls.
I am not sure, your request makes sense as you state it.
RestAssured is just a framework to support you with testing. You can also write unit tests, that do the equivalent of PUT and DELETE (basically the internal implementations), which then modify the database state.
Or you can only issue HEAD and GET requests with RestAssured and not modify the database state by this.
Both of the options will only test parts of the code path if you leave any updates out, so your issue is orthogonal to the selection of RestAssured or hand written unit tests.
Of course you can mock your backend away, but either the mocks are trivial and you don't gain any insight. Or they are complex and you will need separate tests to assure that the mock objects to what you think they are doing.
In order to perform integration tests on a REST Spring MVC Web Service, the SpringSource team has provided a new library called spring-test-mvc, which is now integrate to spring-test.
http://blog.springsource.org/2012/11/12/spring-framework-3-2-rc1-spring-mvc-test-framework/
For my special purpose, it is more adapted than Rest-Assured.