Rest Assured with TestNG

I was working with a test automation framework with cucumber, selenium and TestNG.

According to the requirement, had to have hybrid test architecture to cater to use cases. Hence decided to do REST API testing with Rest Assured.


  • Maven based Java project
  • BDD method used via Cucumber
  • Selenium for automating UI use cases
  • TestNG used to run tests


  • Integrating REST API related automation tests


  • Integrate Rest Assured Library and using it within the framework

Maven Dependency


Remember to add <scope>test</scope> within above dependency, if you want to limit your scope.


Test Class Implementation

I have used TestNG to run cucumber classes as follows:

@BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());

@Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {

public Object[][] features() {
return testNGCucumberRunner.provideFeatures();

@AfterClass(alwaysRun = true)
public void tearDownClass() {
Reporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));

According to my framework, I will be writing a test case inside of cucumber step definitions. If you need a reference for direct integration of Rest Assured with TestNG to follow these [2, 3].

Test Class With Rest Assured

RestAssured.baseURI = "";

//HTTP request
RequestSpecification httpRequest = RestAssured.given();
//Getting response 
Response response = httpRequest.request(Method.GET);
//Response response = httpRequest.request(Method.GET, "/city");

//Getting response body to verify/assert
String responseBody = response.getBody().asString();
System.out.println("Response Body is => " + responseBody);

For more functionalities in REST Assured and easy validations for JSON responses please refer this [1].

Enjoy resting more with REST Assured Testing ;)