There are many benefits of writing unit tests.
- The test we write can serve as a documentation of what the code really does.
- We are more comfortable in refactoring without fear— the tests will catch any existing breaking functionality.
- Unit testing helps us to decouple code. To make our implementation code testable, we have to design it in such a way that each object is decoupled from the other.
- It helps us to reduce technical debt. We struggle to write tests because our implementation design is complex. We have to simplify it to test it properly.