I am working in a rest-assured tool to automate API's. I am using java language. I did a sample API automation. I want to improve. So I want to know the best practice for rest-assured API automation. Here is my code.

package com.restapi.test;

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

 * Created by naveen on 28/2/17.
public class baseUrl {
   public void setup() {
      /*String port = System.getProperty("server.port");
      if (port == null) {
         RestAssured.port = Integer.valueOf(8080);
      } else {
           RestAssured.port = Integer.valueOf(port);
      String basePath = System.getProperty("server.base");
      if(basePath==null) {
         basePath = "/tbiauth/";
      RestAssured.basePath = basePath;

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

 * Created by naveen on 28/2/17.
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[][] {

I want to know if I am doing this the right way and how can I improve?

I especially want to know if there is a pattern that everyone uses, and what is the best practice for test data: should I keep it in dataprovider annotations or use a separate property file?

  • 1
    What kind of test cases are you needing to write? Why this particular number? What is the purpose of your tests? Without this information, we can't really help you.
    – Kate Paulk
    Feb 28, 2017 at 16:48

2 Answers 2


I don't think that best practices vary just because the underlying technology is rest-assured.

We use cucumber to organize our tests. The cucumber steps are written in java. Some of our tests are UI oriented (browser) while others are API focused. For the latter we use a mixture of rest-assured (for web endpoints) and DAO (for accessing database and business intelligence data warehouse back ends). For the former we use Selenium WebDriver.

Cucumber supports Behavior Driven Development. Some of the Given, When, Then statements implement web testing. Other steps implement web endpoint testing using rest-assured. And yet other steps implement back end testing of databases/BI. I use general tags such as @ui, @ep and @dao to coarse group the features and fine grain tags to group those same features by story and/or objective.

UI based test execution is time consuming. End point 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.

  • Hi, I'll be thankful to hear how do you run RA requests in parallel or at least get some pointer to a web resource about it. Thanks!
    – dushkin
    Jul 9, 2019 at 12:52

Write a separate RequestFramingHelper class that includes respective rest_assured methods to test HTTP GET, PUT, POST. This is a good way of organizing your code. Then you can call these java methods to trigger your respective HTTP method. A separate ResponseValidation helper class to validate response code, mandatory tags present in the response, converting the json respons eto a POJO etc., Secondly to develop an automation framework; Use Cucumber, as it is similar to rest_assured given, when then concept. It is easy to learn. It also provides data driven ability using Scenario Outline examples, Data tables concept.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.