In the past, I’ve tested webhook handlers in a much more primitive way: I would trigger the webhook, print out the request the service (like Trello) sent to my webhook handler, and then write a test that calls the webhook handler with the same data.
That approach works well in simple cases, but suffers from two key limitations. The first limitation is that Trello may change its webhook format, so you would manually need to update your test’s data every time.
The other limitation is more subtle. It’s easy to generate the test data for one particular webhook case, like updating a card. But as your app gets more sophisticated, you’ll want to test more cases. That means, every time you want to write a new test case, you’ll have to figure out how to trigger the correct webhook manually.
By putting the code that triggers the webhook in the same test case that tests your webhook handler, you’re building up a framework for how to trigger the correct webhooks. That makes it easier to build more webhook tests.