Automated Testing of REST Services

Hello guys, I have been busy these days, for this reason I am a little late.

In my new project I have been working with web-services and I think this could be useful if you want to do automated tests of Rest Services. I summarise the post, because I don’t agree 100 % with this guy. He says that if you are testing the web service you don’t need to test the client, but the behaviours are different, so you still need test the clients, not the data but the behaviour.

Integration tests were more complex task at that time because such tests imply usage of some mock frameworks. Since an API is consumed by different clients (smartphones, desktops…), make sense to gather a group of tests which check a common logic for all types of clients and to highlight the client-specific test scenarios to focus on a client specific logic. The logic works with data which was already tested in API layer. Such approach gives us an amazing testing strategy. We just need to pay all attention to a UI and some specific features instead in different clients: mobile, web, etc. BUT we still need test different clients, the difference is: We don’t need to test the data, just the behaviour of the client 🙂

 

Automated Testing of REST-services

In my experience I have been testing REST-services manual and automated. The framework that we are using here is Abdera to generate the xml and HTTP Client to post the xml on the server. But this guy is using REST-assured library . It is very easy to use and it works well with the most popular java testing frameworks such as TestNG, JUnit and Hamcrest.

@Test
 public void getLandLaordTest() {
 given()
 .contentType(ContentType.JSON)
 .pathParam("id", "DoYlvMXN")
 .when()
 .get("/landlords/{id}")
 .then()
 .statusCode(200)
 .body("firstName", equalTo("Sam"))
 .body("trusted", equalTo(false));
 }

 

Ok, guys it is this, see you next week !

Source: http://java.dzone.com/articles/automated-testing-rest?mz=62823-enterprise-integration

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: