Automattic / vip-2016-tdd-plugin

Skeleton plugin used as basis for TDD exercise at the VIP meetup, May 2016
5 stars 1 forks source link

Consider integration tests for your WP REST API endpoints #1

Open danielbachhuber opened 8 years ago

danielbachhuber commented 8 years ago

Hi!

On behalf of Pantheon, I'm writing a tutorial on why integration tests are critical for your WP REST API endpoints, and how you can go about writing them.

Given your use of register_rest_field(), I think you could benefit from reading and applying the tutorial. And, because the tutorial isn't yet published, I'd very much appreciate any constructive criticism you have, so that we can make the tutorial an evergreen resource for the community.

Thanks in advance for your time. Happy to take any questions, comments, etc. you might have in this Github issue, or on the document itself (you'll need to be signed into Dropbox).

gravityrail commented 8 years ago

Hi Daniel,

Thanks for the input! I read you post but I wasn't sure exactly which pieces we were missing. If you submit a PR I'd be happy to review and merge it into this tutorial code (and I'd learn something new in the process, which is great).

Thanks again, Dan

danielbachhuber commented 8 years ago

I read you post but I wasn't sure exactly which pieces we were missing.

More so, I wanted to run the tutorial by you to see:

  1. Whether you learned anything from it.
  2. How well you thought it communicated the topic.

Yours is the only repo that actually had tests :)

If you submit a PR I'd be happy to review and merge it into this tutorial code (and I'd learn something new in the process, which is great).

I've submitted a PR with a few suggested changes (#2).

Overall, I'd recommend being much more liberal on the tests you're writing for error conditions. Clients will always send your application unexpected or incorrect data. If your endpoints can provide consistent, clear, and expected responses, then the client developer's life will be greatly improved (as they won't have to spend hours trying to debug cryptic errors in an application they don't have access to). If you write one test for a successful request, write 4 or 5 for the permutations of erred requests.

danielbachhuber commented 8 years ago

If your endpoints can provide consistent, clear, and expected responses, then the client developer's life will be greatly improved (as they won't have to spend hours trying to debug cryptic errors in an application they don't have access to).

Case in point:

image