Maciej Gawinecki, Ph.D.

Logo

Software Engineer

View My GitHub Profile

13 June 2016

Isolating bugs with REST services

by

REST-assured is a popular Java library that makes testing REST services easier. For the last few months we have used it to automate tests for a complex authentication flow. Large part of tests consisted of multiple REST calls, checking system behaviour in different states. Finding bugs was one challenge but reproducing them was another. Particularly, we struggled with:

All those problems can be addressed with cURL. cURL is a popular command line tool available for many platforms and with many *nix distributions it comes pre-installed, so a dev can easily reproduce an issue. Initially, I was crafting those curl commands manually but this scaled poorly. Other platforms for testing offer automatic generation of curl commands from HTTP requests (Chrome Developer Tools, Postman add-on for Chrome, Firebug add-on for Firefox, Ok2Http client), but REST-assured was missing that.

So I’ve created a small library, curl-logger.

How does it work?

Imagine you’re trying to send HTTP GET request to google.com with REST-assured:

given()
    .config(curlLoggingConfiguration())
    .redirects().follow(false)
.when()
    .get("http://google.com")
.then()
    .statusCode(302);

curl-logger will log it as the following curl command:

curl 'http://google.com/' -H 'Accept: */*' -H 'Content-Length: 0' -H 'Host: google.com' -H 'Connection: Keep-Alive' -H 'User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_45)' –compressed –insecure –verbose

You will find more details how to setup a library on the project page.

Waiting for your feedback

The library generates curl commands from an actual request rather then only request specification you wrote, so if a HTTP client in your test accepted server cookies, they will be included by curl-logger as well. Currently, the library supports multiple HTTP methods, multipart/form and multipart/mixed content types and handles file attachments.

If you find it useful, encounter a bug or miss a feature, let me know.