Adil Akhter's Weblogs

Me, My Thoughts and My Journey ....

Why Unit Testing is so important?

Why writing unit tests are so important - lets consider a development team developing a module( call it - [A])did not consider the unit testing that seriously. What happens to that module -

1. [A] produced lot of Bugs in the development phase since it was not tested adequately. And while fixing it- [A] produced severe impact on other modules too because integration was failing again and again. So, the dependent module had to change as well to stabilize whole Delivery.

2. That's not the end of misery. In the release testing, huge amount of bugs identified which also produced from the uncertain behavior of [A]  and fixing those become a hell of a job for the developers. Just to show you one old basic diagram of software development life cycle -

image

3. After the deliverable delivered to the client - Developers could not take pride for that because they were not confident whether they delivered a Good Product( from a developers perspective, I think its really crucial to deliver something from which you can take pride).

4. [A] became more susceptible and fragile day by day. And developers become really reluctant and was not comfortable to change the codes for any change request because of the code's inherent fragility.

5. Refactoring become very error-prone and troublesome.

So, after some time - Developers started calling [A] as "Dead Zone" or Legacy Code because [A] become quite impossible to manage.

Now if we go back to the days when the developers were planing or starting the development process using our Time Traveler- what would you advise them?  :)

The situation that I just described,  its not new to most of the developers developing for a long time. That's why some intelligent people in agile world sit together and come up with some basic rules and practices that we must follow to make our product worth taking pride. One of them is writing Unit Tests for your codes considering all the test criteria considering -

1. Unit Tests are the first users of your Unit who ensure that your own Creation  is working that way you wanted to. Remember - "Taking pride". It become much easier to achieve.In addition, Learning Curve become much higher -because, you get to know very explicitly what are the cases you missed while writing unit tests initially that produce bugs. That way it makes you much mature developer day by day.

2. Unit Tests are the living description how the Unit should work. Any one new to your unit as a developer , should just need some time to go through the Unit Tests to get the Idea how the unit should work.

3. Unit Tests are the tools that make integration much easier.

4.Last but not that least - Refactoring was never been so much easier if there were Unit Tests.

Any comments or suggestions on this post is most welcome.

Comments

Sheldonp said:

Thank-you for the post.  I would be interested in seeing the graph for 'Team B' who leveraged unit testing.  Does the cost of fixing defects also rise but not as steeply, remain constant, or a combination of both?

# April 23, 2008 12:47 PM

Dan Kaplan said:

One thing I've found to be true: unit tests become harder to add the longer you wait.  You often discover you have to modify some code that already seems to work to make it easy/possible to unit test it.  Paradoxically, you may end up breaking code by adding the unit test.  

# April 24, 2008 8:25 PM

Lior Friedman said:

It was an interesting post, thank you. you really emphesized the "taking prid" issue. why do you feel this is such an important aspect?

# April 27, 2008 1:18 PM

Md. Adil Akhter's Weblogs said:

I n Test Driven Development  as a developer we spend significant amount of time in writing unit

# May 4, 2008 6:16 AM

Adil Akhter said:

Hi Lior Friedman,

I emphasize on "Taking Pride" because I believe that’s the driving force for a developer keep up the good work constantly. By mentioning about “Taking pride” – I tried to refer to a concept known as - “self-rewarding”.

At the end of the day, when a developer thinks inside his mind  - “Well I did a great job” , that instantly brings the encouragement to repeat the same success story in the next day morning when he/she start writing code a IDE.:) And opposite of this situation don't bring a good result.

Thanks for visiting the blog.

/Adil  

# May 4, 2008 2:18 PM

Brian Mains Blog said:

If you haven't heard about the series I'm doing, the Calendar Day View project is one that I'm

# May 17, 2008 7:38 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)