Spec your tests before writing them
If you’re struggling to get developers on your team to write integration or E2E tests when building new features, here’s a quick technique to help.
I generally find that the root cause of this is not laziness, but rather that they don’t understand what they should be testing. With teams new to serverless, this can be a problem as they often aren’t sure of the failure modes of the services they’re using.
Here’s the technique (which uses the Jest framework for JavaScript/TypeScript):
- Create a new test file for the feature being built
- Write out a list of
it.todo
(ortest.todo
) statements for each test case, including happy paths and error cases. Add comments in where the test title isn’t sufficiently descriptive. - Review the list with a colleague (over a PR or in a pairing session) before starting on implementation
That’s it!
Just taking the time to think through the different cases that your code needs to handle without the pressure of thinking about implementation details can really help clarify your thinking, improving the quality of both your test code and the application code.
Paul Swail
Indie Cloud Consultant helping small teams learn and build with serverless.
Learn more how I can help you here.
Join daily email list
I publish short emails like this on building software with serverless on a daily-ish basis. They’re casual, easy to digest, and sometimes thought-provoking. If daily is too much, you can also join my less frequent newsletter to get updates on new longer-form articles.