3

This question already has an answer here:

All REST API's that I've built have always had a good series of unit tests to verify that they are working as expected.

One downside to this approach is that the testing almost always happens on either a development or a CI server and they don't verify everything is running correctly on a live or a clone of the live servers.

Is anyone able to recommend any additional tools for checking the API at a higher level when deployed to a server.

Thanks Scott

marked as duplicate by NarendraC, Kate Paulk, Yu Zhang, IAmMilinPatel, Bharat Mane Nov 10 '16 at 12:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You can use PostMan (free Chrome App) to create tests and save them into a collection. You can then fire off the collection as needed (like after a build).

2

I would suggest ReadyAPI/SoapUI NG Pro. It can be used to test and assert against the REST service.

One of the param options in the Pro version, run via command line, is to set the environment (-E) which means you can run the same suite against multiple endpoints fairly trivially as steps within your CI tool (or whichever method you prefer).

2

First of all, as it is always recommended focus on low-level test as much as possible and write high-level test as few as possible (e.g. Martin Fowler -Test Pyramid).

For high-level web-service test besides what others mentioned, I would recommend:

  • Frisbyjs: Easy to config and use. Suitable for end-2-end web-service testing. No mocking/stubbing is possible in contrast to others e.g. rest-assured.
  • Give Python a try ! It is as easy as:

    response = requests.post(url, data=data_json, headers=headers)
    assert (response.json() ...)
    
1

If it's Java, you can use RestAssured:

get("/lotto").then().assertThat().body("lotto.lottoId", equalTo(5))

Another option for JVM based language is Groovy's RestClient which is going to look even better:

assert 5 == rest.get('/lotto').data.lotto.lottoId

Note that the number of these tests should be lower than the number of unit/component tests devs wrote. These tests will be slower.

Often it's also possible to re-use the very same Component tests Dev wrote, but run them in 2 modes - as System tests and as Component tests. You'd just need to create an abstraction that separates the way tests access the SUT. In most cases though it's not necessary and just a small number of System tests is enough.

0

First list out the rest actions you are supporting and the actual URL's in your application. These are also called endpoints of course.

Then create test skeletons and templates that can be used and applied for each of the supported rest actions.

0

I would suggest using Rest Assured which is a Java Library to test Rest API.

You can integrate it with your existing UI Testing Framework if you have one. Below is the example of automating GET Request using Rest Assured:

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static com.jayway.restassured.RestAssured.*;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;

public class GetStatusCodeTest {

 @BeforeClass
 public void setBaseUri () {

  RestAssured.baseURI = "https://maps.googleapis.com";
}

@Test
public void testStatusCode () {

  Response res = 
  given ()
  .param ("query", "restaurants in mumbai")
  .param ("key", "Xyz")
  .when()
  .get ("/maps/api/place/textsearch/json");

  Assert.assertEquals (res.statusCode (), 200);
 }

}

Here we check whether the response code is 200. If yes then the test has passed.

A detailed tutorial on Rest Assured can be found at below link:

https://restservicestesting.blogspot.in/

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