12

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:

  1. Is the rest assured is the best tool to use?
  2. Does Play framework is better?
  3. I found many other tool like Jmeter, RightAPI etc. to test RestAPI. But I dont think this is automable. Am I right?
CodeSlave
  • 425
  • 6
  • 21
undefined
  • 3,464
  • 11
  • 48
  • 90
  • What let you think that tests created with automated testing frameworks wouldn't be "automatable"? Your question looks very strange to me... – Aurélien Bénel Jan 24 '17 at 13:59
  • If you have hard times configuring "heavy" frameworks, you may use lighter frameworks like [Frisby.js](http://frisbyjs.com). – Aurélien Bénel Jan 24 '17 at 14:01

3 Answers3

6

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.

Schobster
  • 101
  • 2
  • 2
4

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

creichert
  • 538
  • 1
  • 3
  • 7
0

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: enter image description here

Steps

  1. We can prepare our APIs in JMeter

  2. Configure the tests in non GUI Mode in Jenkins.

  3. Install and Configure the Performance plugin in Jenkins.

Sajan Jacob K
  • 496
  • 5
  • 8