Introduction
Unit testing helps check small parts of your code to make sure they work right. It finds mistakes early so fixing is easier.
When you write a new function and want to check it works as expected.
Before adding big changes to your code to avoid breaking things.
When fixing bugs to confirm the fix works and nothing else breaks.
To make sure each part of your program does its job correctly.
When you want to automate checks so you don't test manually every time.