Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  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?
like image 794
undefined Avatar asked Feb 15 '14 18:02

undefined


People also ask

How do you automate API testing in Jenkins?

To add ReadyAPI to our Jenkins build, we'll scroll down to the Build section, click Add build step, and then select “Execute shell”. In the menu on the left, right-click the test case you'd like to automate. In the right-click menu, you should see Launch Test Runner - click it and you'll see the TestRunner menu.

Does Jenkins support continuous integration?

Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build.

How does Jenkins achieve continuous integration?

In Continuous Integration, after a code commit, the software is built and tested immediately. Jenkins used for orchestrating a chain of actions for Continuous Integration in a software project. Before Jenkins when all Developers had completed their assigned coding tasks, they used to commit their code all at same time.


1 Answers

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.

like image 100
Schobster Avatar answered Oct 14 '22 16:10

Schobster