Debugging is the process of finding and resolving bugs or defects in software. When various subsystems or modules are tightly coupled, debugging becomes more complex and time consuming. Sometimes it takes more time to debug a program than to code it. However, this can be avoided or reduced with the help of unit tests since unit tests break down the functionality of the program into discrete behaviors which can be tested as individual units.
According to F.I.R.S.T principles, unit tests should be Fast enough so that a developer won’t be discouraged from using them and should be Independent of each other in other words Isolated from its dependencies. One of the main advantages of isolated tests that verify a small unit of behavior is to locate bugs by limiting the search area. Furthermore, unit tests should be Repeatable, meaning that they give the same result if run multiple times regardless of the environment. Another principle is Self-validating which means test result ought to be clear whether passed or not without any additional manual checks. Finally, the last letter stands for Timely. Even though, a developer can wait to write unit tests until code is production ready, it is more preferable to test in a timely manner. In this way, not only it will be easier to write the test but also it will give immediate result. By following these principles you are able to write unit tests that improve quality and reduce development cost.