Friday, June 30, 2017

Rest Assured integration tests for jsontest.com


Contents:

1) Introduction
2) Rest Assured GET examples
3) Rest Assured POST examples

1) Introduction

In my very popular Tester's toolbox - an alternative guide I listed few examples of free public APIs that can be used for learning Rest Assured. Recently I have found one more site - www.jsontest.com. Having in mind that my last API test post was almost exactly one year ago I decided to utilize my latest finding and show you few examples. JSON Test API has few excellent functionalities for people who want to learn.

In order to use Rest Assured in your Maven project add this dependency:


2) Rest Assured GET examples

As a nice beginning I suggest to test ip.jsontest.com. This endpoint prints your current IP address. Here is simple test case that looks pretty much like copy/paste from excellent getting started guide. Please note that you would most likely have to update partOfMyIp String.


Second endpoint - date.jsontest.com returns date in three formats. Dealing with a time in tests can be tricky (flaky) so I decided to assert only date in MM-dd-yyyy format.


There is also echo.jsontest.com/key/value/one/two endpoint that gets the values from URL.


Another endpoint - cookie.jsontest.com sets the cookie as response. Here is the test that asserts if the cookie was set.


The most fun you may get from headers.jsontest.com. This endpoint reads headers from your request and prints them in response. I decided to send XML with UTF-8 enconding and assert Content Type.


3) Rest Assured POST examples

Those were GET examples. Now we would use POST method and send some data. Please note that .queryParam() method has to be defined in given() section which is a little bit strange for me. I'd rather code that in when() section after providing url.

First endpoint - md5.jsontest.com/?text=text takes your text and returns it together with calculated md5 checksum.


Final endpoint which I decided to test is validate.jsontest.com. It takes 'json' queryParam value and validates if it's parse-able (i.e. if it's correctly formatted json). Below is simple happy path:


And negative path:


As usual all code from this post (+1 extra test) and from my previous Rest Assured Post  is available on my GitHub project.

No comments:

Post a Comment