Thursday, January 12, 2017

Why we need to write Unit test cases

Alright so there is been a lot of discussion on writing Unit Test Cases.

First question that a developer asks me is why do we write unit test cases and how does it help us.

My only answer to the question is that It helps you to fail faster than later.

Let me explain you what do I mean by that - So before 3 years I used to have an excel sheet in which I used to put all the conditions and test against those conditions which was very MANUAL in nature.

World was quickly moving forward and I was stuck in the world of manual era.Needed to adopt to moving world and then I started exploring the automotive world that is when I realised the rest of the world writes Unit test cases using frameworks like Ms Test, Nuint

So why do we write Unit test cases - Every developers  job is to ensure that he writes code in a way that it delivers required business value. Essentially the code that a developer writes. Needs to be the best piece of code and a quality one.

So we just refereed to quality keyword above. So what do we mean by that and how do we measure quality.

The answer to this is writing Unit test cases - Tan ta daaa. Wow so do I mean by writing test cases we achieve quality code or build quality product - NO NO NO obviously No. It depends on how you write the code.

You can write bad code and still be able to write unit test cases for the same - Some of my colleagues write Unit test cases without assert and explain me saying that it is at-least covering the code -Management will be happy if there are more unit test cases and code is covered

Alright let come to the point. According to me why do we  write unit test cases.

1.It will help you think like a end user.

2.It will help you have control on the code you write.

3.It will help you have grip on the functionality that you are working on and also helps in delivering the required business functionality.

4.Your thinking capability would grow to another level thus you will get a zeal to write better code.You will refactor the code yourself.

5.Important thing You would understand what SOLID principle mean and how you use them which working in the project.

According to me a piece of code that is non testable is not the best piece of code that is written.

Happy Coding :) :) :)