1

I have some got rest API's for testing with rest assured. How to automate using with rest assured ? What are the different cases that should I need to test ? This is a sample API .What are the test cases that I need to test ? I want to know about rest api testing comcept.... here is the sample API what should I do ?

appinit (GET)
======= 

http://th/m/v2/appinit?
clientId=3&
appName=qberCli



{
"status":true,
"app_secret":"c6b8fff7accd0daf75f1c5757ce11",
"dt":1486100177
}

Here is a sample API testing:

    package  com.qber.test;

    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;

    import static com.jayway.restassured.RestAssured.given;
    import static org.hamcrest.CoreMatchers.equalTo;

   public class bookToken {
    @Test(dataProvider = "appinit")
    public void md5JsonTest(String clientId,String appName)
 {

        given().
                parameters("c", clientId).parameters("a",appNmae).
                when().
                get("http://th/m/v2/appinit?
    clientId=&
    appName=").
                then().
                assertThat().
                body("md5", equalTo(md5Hash));
    }

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

        return new String[][] {
                {"3","qbercli"}



        };
    }

}

What are the addtional test cases that I should write ?

1

In terms of more cases that you need to test, here are some examples:

  • get with an invalid client-id, expect error
  • get with empty app-name, expect error
  • get without passing any query string parameters
  • validate that the md5 hash returned is as expected
  • validate the payload, that it has 'status' and 'dt' as not-null
  • validate the format of the payload data (if it is a string or valid date etc)

I recommend Karate for testing, it is much simpler than REST-Assured. (disclaimer: I am the dev)

0

If you considering automating API's, I would suggest you to automate it in a traditional way using either

  1. Java HttpURLConnection
  2. Apache HttpClient

Please take a look at this link for more info on above 2 points.

  • I edit my post please review – toastmaster Feb 17 '17 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.