Creating a Unit Test
In the last decade unit tests have become popular. But many times, the true goal of unit tests are not well understood, perhaps due to the naming. It's true that unit tests are very helpful in terms of finding bugs in our software.
It is useful to write unit test even if you have a function with a small amount of code. The reason is although unit tests are for hunting bugs there is one category of bugs they are primarily helpful for finding. That is regression. Regression usually happens through the breakage of existing functionality as we add new code.
With regard to regression, a unit tests acts like a fusebox. It will ensure that if we break existing functionality without realising, the older tests start to fail. And if they don't, the programmer will feel comfortable as he or she would know that it is unlikely that existing functionality is broken. Although unit tests do not guarantee this kind of safety, it is an invaluable asset if you constantly add to or change...