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.

111 thoughts on “Rest Assured Request and Response Specifications”

  1. Magnificent web site. Plenty of useful info here. I am sending it to a few friends ans additionally sharing in delicious. And naturally, thank you on your sweat!

  2. I truly appreciate this post. I?ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again

  3. Reginia Thombs

    well if programmers don’t understand how to use it, there is hope for me 🙂 as I have a better understanding now

  4. порно римминг

    As a Newbie, I am always searching online for articles that can help me. Thank you
    My website: анилингус порно

  5. Graham Rowland

    What’s Happening i’m new to this, I stumbled upon this I’ve found It positively helpful and it has aided me out loads I hope to contribute & help other users like its aided me Good job

  6. 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.

  7. 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!

  8. 토토배팅사이트

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

  9. 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.

  10. 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.

  11. 먹튀사이트

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

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

    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 – แอ พ เครดิตฟรี กดรับเอง

  13. 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

  14. 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!

  15. 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!

  16. 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.

  17. 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!

  18. 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.

  19. 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?

  20. 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.

  21. 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!

  22. 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.

  23. 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.

  24. 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.

  25. 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!

  26. 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.

  27. 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.

  28. 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.

  29. 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.

  30. 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!!

  31. 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!!!

  32. 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. . . . . .

  33. 유로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.

  34. 유로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.

  35. 유로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.

  36. 유로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.

  37. 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!

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

  39. 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!

  40. 유로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!

  41. 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.

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

  43. 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.

  44. 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.

  45. 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.

  46. 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.

  47. 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!

  48. 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.

  49. agen sbobet resmi

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

  50. 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.

  51. 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.

  52. 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.

  53. 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

  54. 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 *