Since 2015 I’ve been writing unit tests, consistently.
Here is a 16-Step guide to starting your own unit testing journey.
When starting:
- Write smaller functions
- Make functions deterministic
- Write functions with no side effects
- Write tests to confirm execution paths
- Practice by writing tests that feel “worthless”
- Write the tests that come naturally. X in expects Y out
When you’re comfortable:
- Write tests for all utilities
- Write tests for all assumptions
- Ignore test coverage percentage
- Write tests to confirm object interactions
- Write failure tests for critical pieces of code
- Write tests to confirm responses to outside values
When it’s a habit:
- Write tests before the code (Optional)
- Invert dependencies and keep things testable
- Make unit tests a requirement for code reviews
- Plan to write code from the lens of how you can test it
The process is not instant, don't rush it.
Identify where you are, start small, and make it a priority.