Unit Testing and Why is it Important


In my opinion, one of the most underrated parts in the coding process is testing. Writing automated testing is really important as it ensures all functionalities work as expected. Before you take an automobile to test drive from the showroom, it needs to go through a lot of underground testing to ensure all things work as expected.

Why would you want to test your own code?

You might want to trust your code. The process might feel a bit redundant where you test the functionality that you just implemented. Although this might be true for smaller applications that are not used by a lot of people, when working in a team automated test are really important. Suppose, you added a feature that worked perfectly. One of your teammates, adds a feature to the code base that tinkers something with part of the code that you added. Now the previous functionality breaks. Unless and until you have tests to identify these functionalities, they will only be noticed when the code is run is production.

Advantages of writing Unit Tests

Even if you work alone but are building something that has a large code, the same principle is valid. Testing helps in automated identification of the bugs before shipping the code to production.

Unit testing is writing tests that validate each individual unit(functionality) of the code. It tries to ensure that each functionality is working independently of the other. On the implementation side, you might think it in the form every time you give the function same input, the output remains consistent.

One of the other advantages of unit tests is it enhances the maintenance of the code base. This becomes a real issue when you're dealing with a team or a large code base. When code is being pushed many times a day to a repository, it also helps in Continuous Integration(CI).

In the next post, I will try to show we can write unit tests in python.


Join discussion: