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 {
        public void setup() {

            String basePath = System.getProperty("server.base");
                basePath = "/tbiauth/";
            RestAssured.basePath = basePath;

            String baseHost = System.getProperty("server.host");
                baseHost = "";
            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) {





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

            return new String[][] {


Is my apporach right?

Is there any better approach to this?

1 Answer

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