Rest Assured Request and Response Specifications

These are used to avoid duplication of code for reusable configurations that need to be done for multiple RESTful request and response validations.

Request Specification

‘RequestSpecification’ interface provided by Rest Assured is used to club and extract repetitive actions like setting up base URL, headers, HTTP verbs etc which may be common for multiple Rest calls. The extracted common code can be used in different requests thereby reducing number of lines of code and increasing maintainability.

Illustration:

Consider following JUnit test cases which are written to test an API endpoint.

As evident, most of the request configurations as highlighted by red block are common to both the test cases yet they are duplicated. In an exhaustive test suite this can easily become and overhead to write all these duplicate codes which is also hard to maintain in case some data needs to be changed across all test cases.

Request specifications come handy in such situation by extracting these common test parameters as a separate entity and used across all the test cases. Below example demonstrates the same

As depicted in above figure, we extracted the common request setup in a separate base test case using RequestSpecification interface and used it in the actual test cases. Hence overcoming redundancy and enhancing reusability and maintainability of the code.

Response Specification

‘ResponseSpecification’ interface comes handy in situation where similar set of assertions need to be done for several Rest requests. It achieves this by grouping common assertions into a ResponseSpecBuilder instance and using this instance for validations in multiple tests.

Illustration:

Consider these tests for a hypothetical API.

As depicted, both these tests have 3 common assertions (as highlighted by red rectangle) which are repeated. Now if the API behaviour changes to return different content type, the assertions at 2 places would need to be corrected. This becomes a maintenance overhead.

Below diagram illustrates how the Response Specification helps in removing this redundancy.

105 thoughts on “Rest Assured Request and Response Specifications”

  1. Hey There. I discovered your blog using msn. That is an extremely well written article. I?ll make sure to bookmark it and come back to read more of your helpful information. Thank you for the post. I?ll certainly comeback.

  2. Thanks for a marvelous posting! I really enjoyed reading it, you could be a great author.I will ensure that I bookmark your blog and will often come back at some point. I want to encourage you to ultimately continue your great posts, have a nice holiday weekend!

  3. 토토배팅사이트

    Very good info. Lucky me I ran across your site by chance (stumbleupon). I have saved as a favorite for later.

  4. I’m impressed, I must say. Seldom do I come across a blog that’s both equally educative and interesting, and without a doubt, you have hit the nail on the head. The issue is something that too few folks are speaking intelligently about. I am very happy that I found this in my search for something relating to this.

  5. Having read this I believed it was extremely informative. I appreciate you finding the time and energy to put this article together. I once again find myself spending a significant amount of time both reading and leaving comments. But so what, it was still worth it.

  6. 먹튀사이트

    It’s hard to come by educated people on this subject, however, you sound like you know what you’re talking about! Thanks

  7. แอ พ เครดิตฟรี กดรับเอง

    If some one wants to be updated with most recent technologies after that he must be pay a visit this web site and be up to date
    every day.

    my web-site – แอ พ เครดิตฟรี กดรับเอง

  8. The article helped to understand how to use RequestSpecification and ResponseSpecification without any issues. Also, I’d like to thank you for the readable and well-structured article. Thanks

  9. This is without a doubt one of the best articles I’ve read on this topic! The author’s comprehensive knowledge and passion for the subject shine through in every paragraph. I’m so thankful for finding this piece as it has deepened my comprehension and ignited my curiosity even further. Thank you, author, for dedicating the time to create such a remarkable article!

  10. Brasil Rateios

    magnificent post, very informative. I wonder why the other specialists of this sector do not notice this. You should continue your writing. I am confident, you’ve a great readers’ base already!

  11. Brasil Rateios

    Aw, this was a very nice post. In idea I would like to put in writing like this additionally ? taking time and precise effort to make a very good article? but what can I say? I procrastinate alot and on no account appear to get one thing done.

  12. I just like the valuable info you supply in your articles. I?ll bookmark your weblog and take a look at once more right here regularly. I am rather sure I?ll be informed many new stuff right here! Good luck for the next!

  13. Huile de Cumin Noir

    Its such as you learn my mind! You seem to grasp so much about this, like you wrote the guide in it or something. I feel that you simply could do with a few to drive the message home a little bit, but other than that, this is excellent blog. An excellent read. I will definitely be back.

  14. I’ve been absent for some time, but now I remember why I used to love this blog. Thanks , I will try and check back more often. How frequently you update your web site?

  15. I have seen many useful factors on your web site about pcs. However, I’ve the thoughts and opinions that lap tops are still not quite powerful sufficiently to be a good option if you often do tasks that require lots of power, for example video croping and editing. But for web surfing, statement processing, and most other prevalent computer functions they are okay, provided you may not mind the tiny screen size. Many thanks for sharing your notions.

  16. Pretty great post. I just stumbled upon your weblog and wished to say that I have truly enjoyed surfing around your blog posts. In any case I?ll be subscribing to your feed and I hope you write once more soon!

  17. Mireille Russell

    You helped me a lot with this post. I love the subject and I hope you continue to write excellent articles like this.

  18. I really enjoyed reading your post, especially because it addressed my issue. It helped me a lot and I hope it can help others too.

  19. Christa Coughlan

    Thank you for posting this post. I found it extremely helpful because it explained what I was trying to say. I hope it can help others as well.

  20. Hi there, just became aware off your blog through Google, and flund that it iis reaslly informative.
    I am going tto wqtch out for brussels. I’ll appreciate if you continue thiis inn future.

    Nummerous people wil bbe benefited fropm yolur writing.
    Cheers!

  21. Aw, this was a very nice post. In concept I would like to put in writing like this additionally – taking time and actual effort to make an excellent article… but what can I say… I procrastinate alot and certainly not appear to get something done.

  22. If some one wishes to be updated with newest technologies therefore
    he must be go to see this web page and be up to date everyday.

  23. Heyya i amm forr the irst time here. I founnd thiis board and
    I find It really usefgul & iit helped me oout much. I hope too give something
    back and helpp othhers like you helped me.

  24. You have made some decent points there. I looked on the internet for more information about the issue and found
    most people will go along with your views on this site.

  25. Oh my goodness! Impressive article dude! Thanks,
    However I am experiencing problems with your RSS.
    I don’t know the reason why I am unable to subscribe to it.
    Is there anyone else getting similar RSS problems?
    Anyone who knows the solution can you kindly respond?

    Thanx!!

  26. Complicado localizar alguém comentando com tanta segurança sobre
    isso, porém parece que tu domina do que esta dizendo.
    Gratidão por compartilhar teu conhecimento!!!

  27. Hi there very cool blog!! Man .. Beautiful .. Superb .. I will bookmark your website and take the feeds also?KI’m happy to find a lot of helpful information right here within the post, we want work out extra techniques on this regard, thank you for sharing. . . . . .

  28. 유로247가입코드

    Do you have a spam issue on this website; I also am a blogger, and I was curious about
    your situation; we have developed some nice methods and we are looking
    to trade methods with others, please shoot me
    an e-mail if interested.

  29. 유로247가입주소

    Hey There. I found your blog using msn. This is an extremely well written article.
    I’ll make sure to bookmark it and come back to read more of your
    useful info. Thanks for the post. I will definitely return.

  30. 유로247가입코드

    always i used to read smaller posts that also clear their motive, and
    that is also happening with this paragraph which I am reading now.

  31. 유로247가입코드

    I’ll right away grasp your rss feed as I can’t in finding your e-mail subscription link or e-newsletter service.
    Do you’ve any? Please allow me recognize so that I could
    subscribe. Thanks.

  32. You ought to be a part of a contest for one of the most
    useful sites on the internet. I will highly recommend
    this blog!

  33. I am truly delighted to read this weblog posts which includes tons of
    useful data, thanks for providing such data.

  34. This is a great tip particularly to those fresh to the blogosphere.
    Short but very precise info… Appreciate your sharing this one.
    A must read post!

  35. 유로247코드

    Hi there would you mind sharing which blog platform you’re
    using? I’m going to start my own blog soon but I’m having a difficult time making a
    decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking for something
    unique. P.S Apologies for being off-topic but I had to ask!

  36. Thanks for every other informative site. The place
    else may I am getting that type of info written in such
    an ideal method? I’ve a venture that I am simply now operating on, and I have been on the glance out for such info.

  37. Hi there, after reading this amazing piece of writing i
    am also glad to share my experience here with colleagues.

  38. Aw, this was an extremely nice post. Taking the time and actual effort to create
    a superb article… but what can I say… I hesitate a lot and never seem to get nearly anything done.

  39. I’m very pleased to discover this website. I need to to thank you for your time for this fantastic read!!
    I definitely savored every bit of it and I have you book marked to see new stuff in your web site.

  40. Hi, i read your blog from time to time and i own a similar one and i
    was just wondering if you get a lot of spam remarks?
    If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it’s driving me crazy so any help is very much appreciated.

  41. Election Audit

    I’m gone to inform my little brother, that he should also pay a quick visit this website on regular
    basis to get updated from most up-to-date information.

  42. You really make it seem so easy along with your presentation however I to find this topic to be actually something that I believe I would by no
    means understand. It seems too complicated and extremely wide for me.
    I’m having a look forward on your subsequent post, I will attempt to get the grasp of it!

  43. continuously i used to read smaller posts that also clear their motive, and that is also happening with this article
    which I am reading at this place.

  44. agen sbobet resmi

    Hello, its nice article about media print, we all be aware of media is a fantastic source of
    data.

  45. I really like what you guys are usually up too.
    This kind of clever work and reporting! Keep up the fantastic
    works guys I’ve included you guys to blogroll.

  46. Hello there! Do you use Twitter? I’d like to follow
    you if that would be ok. I’m undoubtedly enjoying your blog and look forward
    to new posts.

  47. Its like you read my mind! You appear to understand so much about this,
    such as you wrote the ebook in it or something.
    I think that you just can do with some % to pressure the message home a bit,
    however instead of that, that is excellent blog. An excellent read.
    I’ll definitely be back.

  48. Thanks a lot for sharing this with all people you actually recognize what you are talking about!
    Bookmarked. Kindly additionally consult with my site =). We could have a link exchange agreement between us

  49. I enjoy what you guys are usually up too.
    This kind of clever work and coverage! Keep up the
    fantastic works guys I’ve included you guys to my own blogroll.

Leave a Comment

Your email address will not be published. Required fields are marked *