Unit test is one of the methods to test each of function or module individually.
In my mind, one of the analogies for unit test is slalom skiing. From the start to the end, you are supposed to slide and between a pair of red or blue flags. You cannot simply go straight to the goal. In addition, a red safety net is set where skiers might go out of the course to catch them safely.
Software, apps, or program is a sequence of processes. Each process can be seperately check whether it works as expected or not. This part is equivalent to passing the expected route between a pair of flags. Also, a programmer have to come up with the scenarios when and in which condition each process could fail and then what would happens. This part is similar to the safety net for slalom skii. We need to catch errors by unit test instead of skiers.
If we can cover major scenarios of success and failure, the module would be more maintainable and reuseable. On the other hand, the process of writing unit test cases force us to think ahead what you would like to achieve specifically, what is the ideal case and worst case etc. Therefore, it will help us to create better code.