Do you have questions ? We got the answers!

Ask a question:

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

Solved 1 Answers 79 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

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 433 pointsSunilBhaskar

    41 questions 15 answers32 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 363 pointssumitkumarwatts

    0 questions 13 answers0 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...