DEV Community

Mohammad Faisal Khatri
Mohammad Faisal Khatri

Posted on

How to write API Tests using REST-Assured and OkHTTP?

❓ What is REST-Assured?

REST Assured is a Java library that provides a domain-specific language (DSL) for writing powerful, maintainable tests for RESTful APIs.

❓ What is OkHttp?

OkHTTP is an open source project designed to be an efficient HTTP client:

  • HTTP/2 support allows all requests to the same host to share a socket.
  • Connection pooling reduces request latency (if HTTP/2 isn’t available).
  • Transparent GZIP shrinks download sizes.
  • Response caching avoids the network completely for repeat requests.

❓ How to write API Tests using REST-Assured/ OkHttp?

As many of you know that REST-Assured and OkHttp are currently in demand for writing automation tests for APIs. I was learning about Rest-Assured and OkHttp, an idea just popped into my mind, why not save the code on github so it would serve as a learning material for beginners.

Hence, I created and posted the code which I wrote, on github, in the following repository. It has API testing example codes for GET, POST, PUT, PATCH and DELETE requests using REST-Assured as well as OkHttp:

OkHttpRestAssuredExamples

💡 REST-Assured or OkHttp?

Interesting question! While I was running the tests, I found an interesting thing which caught my attention. The execution speed of OkHttp when compared to Rest-assured was far better.
Checkout the following blog for more details about REST-Assured and OkHttp performance with reference to execution time:

REST-Assured or OkHttp?

In the end, I would like to mention that it all depends on the project and your requirement for choosing the framework to write and execute the tests. Everything has something unique, its up to you how you choose!!

Top comments (0)