comparing two REST services to each other

2019-09-18 08:01发布

Does anyone have any tips on writing tests that compare two REST services? We are doing this as a form of regression testing.

I was hoping to do something along the lines of:

  1. send a GET for "/1" to both services and compare the results
  2. send a POST to both services, and compare the results
  3. send a PUT to both services, and compare the results

The idea is that:

  • every operation is sent to both services
  • the results should be identical

The REST services are written in Java/Jersey, so using that would be ideal, but what have people found to be useful?

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-18 08:25

I would use jUnit and some of the example test cases from the Jersey source as a starting point. Without knowing specifically how you want to determine "identical" responses, you can make a request to each in your test case and iterate through the response, convert it to a string and test for equals(), etc. Here is an example of a JSONP from JAXB test.

查看更多
Melony?
3楼-- · 2019-09-18 08:26

Since this is a broad, non-coding question not strictly related to java, here are some related links:

Anyone feel free to edit my answer to add more alternatives demonstrating API response comparison

查看更多
\"骚年 ilove
4楼-- · 2019-09-18 08:35

Write Junit to get the response objects from both services. And then do the comparison in Java as you do normally for the objects.

But why do you have to write two services that does the same thing and return same results? Atleast I assume the response objects schema is different between two services.

查看更多
登录 后发表回答