Introduction
Unit tests help check small parts of your code to make sure they work right. They catch mistakes early so your app stays reliable.
When you want to check if a function returns the correct result.
When you change code and want to make sure nothing else breaks.
When you build a new feature and want to test its parts separately.
When you want to avoid bugs before users find them.
When you want to write code that is easier to maintain and improve.