What to test?
Testing software is not an easy task. Even senior developers struggle to make it clear what needs to be tested. If you don't know what you are going to test, your tests are probably wrong.
In this article, we are going to give you practical examples of what to test in your backend code, this applies to any programming language. The important part is the concept.
Integration Tests
Tests ensure your code behavior is correct.
It ensures that when given some initial program state, you ended up with a given final state.
Integration tests are the best cost benefit test that you can have.
Integration tests, tests the code like the end user would test it.
When doing Integration tests, you just test public interfaces, you don't test internal functions.
Let's see what exactly you should test in your backend code, given some scenarios.
What to test in an API?
- validate the API return success for success cases
- validate the API return error for error cases
- validate the API is idempotent
- validate the final state of the database is correct
- validate if calls the correct jobs
- validate if creates the correct sms, emails, whatsapps
- validate if the external API requests are being called correct
What to test in a GraphQL Operation (Query, Mutation, Subscription) ?
- validate the response is correct
- validate errors
- validate the final state of the database is correct
- validate if calls the correct jobs
- validate if creates the correct sms, emails, whatsapps
- validate if the external API requests are being called correct
What to test in a worker job?
- validate errors
- validate the final state of the database is correct
- validate if calls the correct jobs
- validate if creates the correct sms, emails, whatsapps
- validate if the external API requests are being called correct
In Conclusion
I hope these practical examples makes your tests making more sense to you.
This is how Woovi tests, and this avoids many regressions and silly bugs.
Always start with the simplest test case, the happy case, and keep adding more and more edge cases to squish bugs.
Woovi
Woovi is a Startup that enables shoppers to pay as they like. To make this possible, Woovi provides instant payment solutions for merchants to accept orders.
If you want to work with us, we are hiring!
Photo by Douglas Lopes on Unsplash
Top comments (0)