How to do conditional comparison of service/ Web API responses?

How to do conditional comparison of service/ Web API responses?



Some context:
Testing for 200 regression use cases for web API/WCF service is real pain and I want to automate it.



I am creating a tool which will automate "before my change" and "after my change" result comparison for given web api or wcf request and I should be able to ignore some tags for comparison which will be unique in both response such as response time, request execution time.



So far I am able to create two folder before and after, before contains response for all the use cases in json/xml format before my change and after contains response after my change for same operation or Web API.Files in folder are saved based on use case name.


after before
useCase1.xml useCase1.xml
useCase2.xml useCase2.xml
useCase3.xml useCase3.xml



In code I have two object for one given file in json format(I read xml and converted it to json as there is possibility that folder may contain json responses). I compared both objects and inside a loop ignoring the configured keys such as response time and request execution time.I wrote use case name in a text file if objects doesn't match for human evaluation.



So far I just had to compare all the test for the same operation or Web API, so json object structure of useCase1 from before folder and after folder was same (it differs only when I add new attributes in my change in which case i'll run comparison ignoring the new attributes to see i have not broke any historical stuff)



Question:
I also want to compare response from one endpoint of service with another on conditional basis to check that both the service are in sync when some feature get delivered.(this scenario is only "after change" scenario and user will have to provide two files which need to be compared)
Example:
AccountDetail.xml


<User>
<Account1>
<food>10</food>
</Account1>
<Account1>
<rent>20</rent>
</Account1>
<Account2>
<food>10</food>
</Account2>
<Account2>
<rent>30</rent>
</Account2>
</User>



AccountSummary.xml


<User>
<Summary>
<Account1>30</Account1>
<Account2>40</Account2>
</Summary>
</User>



Now I want to ask some input from user, so they can tell program to add all amount from Account1 from AccountDetail.xml and compare it with Summary/Account1.
Seems like I have to take SQL query kind of input to achieve above but I have no idea what to do and looking for help.So far whatever I have done is in c#, so I'll be happy if suggestions are for c# but I am open to anything which I can leverage. This is internal tool for me and my colleague and not for production.
Even if you think my entire approach is incorrect,let me know how can I correct or improve it.




1 Answer
1



I have some doubts here, I assume - "You are running repetitive test cases as part of regression test"



In such case, as I understand you should use same test case as well as data entries for validation. That way you shield your repetitive test runs from any changes (may be in logic getting tested and data as well). As a result of this you will be in a state to compare your OLD and NEW results of the test run.



Moreover, if you use same data for repetitive testing you are well aware about the asserts to be verified for making the test as pass or fail.






This testing is to simulate near prod env configuration hence data in the service response is coming from database and no guarantee that it will be same between today and tomorrow as many teams use these database for their testing.But chances of change in data between two testcase execution (account Detail and AccountSummary) seconds apart is pretty low.

– A.Learn
Sep 12 '18 at 5:11




Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)