0
What is the best practice for rest-assurerd API automation testing?

Solved 1 Answers 66 Views

Hi all,

I am automating API using rest-assured tool, using JAVA.

My approach is as follows:

package com.restapi.test;

        import com.jayway.restassured.RestAssured;
        import org.testng.annotations.BeforeClass;

    public class baseUrl {
        @BeforeClass
        public void setup() {

            String basePath = System.getProperty("server.base");
            if(basePath==null){
                basePath = "/tbiauth/";
            }
            RestAssured.basePath = basePath;

            String baseHost = System.getProperty("server.host");
            if(baseHost==null){
                baseHost = "http://192.168.1.3";
            }
            RestAssured.baseURI = baseHost;

        }

    }

    package com.restapi.test;

    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;

    import static com.jayway.restassured.RestAssured.given;
    import static org.hamcrest.CoreMatchers.containsString;

    public class KioskRegister extends baseUrl{

        @Test(dataProvider = "start")
        public void md5JsonTest(String access,String device ,String id,String md5Hash) {

            given().
                    parameters("s",access).parameters("m",device).parameters("d",id).
                    when().
                    get("/register/device").

                    then().
                    assertThat().


                    body(containsString(md5Hash));

        }

        @DataProvider(name = "start")
        public Object[][] createMD5TestData() {

            return new String[][] {
                    {"723efb","123456789","17","REG_DEV_EXISTS_1_00"},
                    {"723efb","","17","REG_DEV_PRMS_2_00"},
                    {"","123456789","17","REG_DEV_PRMS_1_00"},
                    {"723efb","123456789","","REG_DEV_PRMS_3_00"},



            };
        }
    }

Is my apporach right?

Is there any better approach to this?

1 Answer

0
Best answer

There is no best practice because technology is rest-assured.

We use cucumber to organize our tests. Some of the tests are UI oriented while others are API focused. For the latter, we use a mixture of rest-assured and DAO (for accessing database and business intelligence data warehouse back ends).

Cucumber supports Behavior Driven Development. Some of the Given, When, Then statements implement web testing. 

UI-based test execution is time-consuming. Endpoint tests and back-end tests have much shorter elapsed execution times. So using a testing pyramid only a small percentage of your tests should be UI focused.

Lastly, we execute our features in parallel to minimize total execution elapsed time.

answered May 1 by Sagar Shah (143 points)
selected May 1 by stbadmin
...