Why write unit tests?
You might be wondering why you should write unit tests. Let me tell you a story from my personal experience. I released a website that I built recently. A few days later, my colleague who was using the website sent me an email with two files that the website kept rejecting. I closely examined the files, and the requirement of having the IDs matched was met in both of them. However, the files were still rejected and the error message said that the IDs didn't match. Can you guess what the problem was?
I wrote a function that checked whether the IDs from the two files matched. The function checked both the value and the type of the IDs, so if the values were the same and the types were different, it would return no match; it turned out that this was exactly the case with the files from my colleague.
The important question is, how can I prevent this from happening? The answer is a number of unit tests for my function.