Rest Assured with TestNG

Dilshani Subasinghe
Mar 4, 2019 · 2 min read

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.


Image for post
Image for post

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();

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

Enjoy resting more with REST Assured Testing ;)





Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store