1

When testing RESTful JSON APIs with ATDD/BDD practices in mind is it good practice to test the structure of the response?

I'm thinking that it could too easily change, thus making for a brittle test. If this is true, then how should one approach testing REST API endpoints? Perhaps only test the status codes?

5

Testing the status could be a good sanity check, but you should be testing the response to ensure correctness.

If the request/response changes then its tests must also change, In the same way when a function's arguments/return-value changes then it's tests must also change.

Ideally you should deliberate carefully before deciding on the request and response and keep it fixed. Otherwise, all of it's clients will break on each change. One way to mitigate this would be to version your REST endpoints so that existing clients would get time to migrate to the newer version without breaking.

  • Good point, at the end of the day it's still the boundary of an interface and shouldn't change too often. – Adam Thompson May 25 '18 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.