Automation Testing


By Test Guild
  • Share:
Join the Guild for FREE

In my last few posts we went over getting started with rest-assured and how to get request using the new given, when, then syntax — now that we have some get request method examples under our belt I wanted to take a look at a few examples of using Rest-Assured to test JSON REST services using the POST method.

Setup – CouchDB

To make this example as easy as possible and not have to setup any sort of authentication, I'll use Apache couchDB. CouchDB is easy to install, stores data as JSON documents and has an easy-to-use API to interact with it. This makes it a great application to use to teach us more about REST testing rest-assured and JSON.

To install couchDB go to:

  2. Click on Download and choose the version you want to us
  3. Once it's installed, enter in a browser. This should bring up your local CouchDB Futton web site.
  4. Next, click on the Create Database and name it “restassured”

  1. Navigate back to Notice that restassured shows 0 docs.

You can also check out my SoapUI – How to Post Json to a Rest Service video for how to install couchDB.

Time to use Rest-Assured to Send a Post Request

For some reason, I had a hard time figuring out how to do this. Whatever the reason, I finally got it to work. Remember — I’m still learning this myself, and posting what I’m learning along the way. There may be better way of doing it, but for now I’m sharing what worked for me to hopefully help get you started if you’re also struggling to get the POST to work.

  • In your IDE, create a new java class named CouchDB_REST
  • Import the following:
import org.junit.Test;
import org.junit.Before;
import static com.jayway.restassured.RestAssured.expect;
import static org.hamcrest.Matchers.equalTo;
  • Create a public method named postExample
  • Add the junit @Test annotation above it.
 public void postExample()
 String myJson = "{\"name\":\"Jimi Hendrix\"}";
     RestAssured.baseURI  = ""; 

     Response r = given()
     body("{\"name\":\"Jimi Hendrix\"}").

     String body = r.getBody().asString();

  • Right click on the and Run As>Junit Test
  • Your test should pass

  • Look for the id in the Console output:

  • Go back to couchDB:
  • Notice how your restassured now shows Number of Documents 1
  • Click on the restassured db link and notice how the ID under the key column matches the id returned in the java console

More Rest-Assured Post


REST-assured How to Check Response Times

REST Testing with Java Part Two: Getting Started with Rest-Assured


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

SafeTest: Next Generation Testing Framework from Netflix

Posted on 03/26/2024

When you think of Netflix the last thing you probably think about is ...

Top Free Automation Tools for Testing Desktop Applications (2024)

Posted on 03/24/2024

While many testers only focus on browser automation there is still a need ...

Bridging the Gap Between Manual and Automated Testing

Posted on 03/13/2024

There are some testers who say there’s no such thing as manual and ...

Don't miss our free webinar How Will Testing Look in the AI Era?  Register Now!