Thursday, September 22, 2005

How TDD improves development speed and is very cost effective

When it comes to automated tests the first impression everyone (including myself) thinks that that would certainly increase the amount of time a certain feature is developed in. However as I started to practice TDD, Test First Programming, increasing the number of tests I came to the conclusion that automated tests actually allow you and the team to develop faster then without.

Move faster ahead in development

A simple comparison of programming vs walking on a rope. When walking on a rope, at a height, with no safety net, walking is much harder , much slower, as the risk is higher. Only very experienced people can walk fast. When having the safety net below, the rist of falling suddenly doesn’t really concern you that much. If you fall, you just go back and try again. You do not jeopardize your life.

With programming, the bigger the code base gets, the hardest is to move further, to change all code, being very afraid, that you could mess it up really good. If you have automated tests, they are your safety net, allowing you to see if one mistake you did affects the system, and you have to roll it back just like falling off the rope makes you go back to the start. A little time is lost, but not the system, you do not need weeks to restore it. The fact that you can see the mistakes you do very fast, makes you a lot braver, having the courage to change a lot, adapt, improve, refactor a lot, then when you don't know what you're doing. The safety net, composed of tests gives you that very fast feedback that something is broken. These tests are also called change detectors. When you do a change, the tests will detect very soon if it breaks something.

Faster development by automating the process

In a recent project, we had a business process on a web application that required the user to go, like in a wizard, trough 9 screens to be able to ship an order. When we were developing it, we had to go 9 pages, filling 9 pages of data to see if the order can or cannot be shipped. We had a lot of times, the order being rejected by reasons that we forgot to fill in some field. This process of filling in all the fields until screen 9 took usually 2-3 minutes, so after 2-3 minutes to see an Exception is not really nice because it just means you have to take another 2-3 minutes to refill and hope this time it will be ok. After a few attempts, I realized this was not the way to go I said what about we automate the whole filling process, , and being a web application we used Selenium (http://selenium.thoughtworks.com) a great functional testing tool for web applications, which did the whole 2-3 minutes manual process in under 4 seconds. Now instead of starting the first page, we ran the test each time until we got the process of shipping right, with all the validations. It took 15 minutes to write the test but it probably spared us of a lot more manual testing. And when it worked, it could be retested whenever we felt like it, in 6 seconds. It was added to the test suite and we made sure that it always succeeded, so we knew all the time that even with our 'big new changes' it still worked.

Minimizing debugging time and cost

Usually people have the tendency to think that by adding automated tests the development time increases. They say that if you have something to implement in 4 hours and doing the tests would take 2 hours, you have just lost 2 hour writing the tests. Coming back with our feet on the ground we can soon realize, that that thinking is superficial as it presumes that the code done in the 4 hours of development is bug free. That is bug free and will stay like that even if the system around it changes, gets bigger etc. The sad truth is that most code is not bug free for the first time, and a lot of time is lost debugging it. In many cases the time to debug is bigger then the time it was developed in and this time usually increases as the time goes. The biggest problem is maybe that usually debugging time is not measurable or it is hard to predict how much time it will take. So 4h+??? = ???

If the bug is discovered by the client, solving it is usually not paid, so it's cost just doubles or grows even more. Many times you end up with a negative balance when saying 4h developing=10$ then fixing the bug 4h=10$. The company ends up with 10-10=0$. And this is a good case.

Automated tests, with a good coverage of possibilities, will reduce even eliminate the debug time and if they are kept in a test suite that is run very frequently will make sure they remain bug free. In this case you use 6h, but you're very sure you've done it right.

Automated tests help you get things right the first time, costing less

A similar sample was with my wife. She went to buy paint for our doors. She bought two cans, one with 0.85 the other with 1.55. When we started painting we quickly realized that the 0.85 paint , needed to be put twice on each door, so is actually costed double: 1.7. Now if she bought two cans of 1.55 we would have paid less money and less effort. The very same goes with automated tests. They seem to cost more then developing without them but they usually end up costing less, as you get the things right the first time and not after the deployment, when you fix the bugs from your own pocket.

I hope the 3 reasons above gave you an idea, why I think developing being backed up by automated tests actually help you develop faster, then developing without them .

16 comments:

Lavfresh said...

I really enjoyed all the great information on your blog.
It really is about time I started my own. I will be linking
it from my website about web hosting provider Would love to know what you think.

Dan Bunea said...

:) Well, I am glad you liked it. And I really encourage everyone to start writing. Whether you write on your blog, articles, books, discussion formums etc it doesn't really matter, as I have benefited in the past a lot from reading other people sharing their experiences and I hope to be able to do the same for others.

Emerald Web Hosting said...

Hey, you have a great blog here!

I have a design hosting web site. It pretty much covers ##WEB HOSTING## related stuff.

We have business and personal web hosting packages. No setup fees. Low cost domain registration, SSL certificates, merchant accounts and web design.

Come and check it out if you get time.

Web Hosting said...

I'm definitely going to bookmark you!

I have a internet service provider hosting site/blog. It pretty much covers internet service provider hosting related stuff.

Very well presented blog!!

Infactahost.com said...

Hey, you have a great blog here! I'm definitely going to bookmark you!

I have a small business web hosting site/blog. It pretty much covers small business web hosting related stuff.

Come and check it out if you get time :-)

Infactahost.com said...

Hey, you have a great blog here! I'm definitely going to bookmark you!

I have a php script utility site/blog. It pretty much covers php script utility related stuff.

Come and check it out if you get time :-)

officialloversguide said...

I enjoyed reading your blog. There is a lot of useful information about easy home based business in it. We offer Turnkey Websites and Reliable Hosting. We also provide a blogging service that will help your site get indexed fast and keep the search engines visiting your site. Click here for more information about easy home based business.
Thank you
TWP Admin

tipsonrelationships said...

I enjoyed reading your blog. There is a lot of useful information about turnkey pharmacy web site in it. We offer Turnkey Websites and Reliable Hosting. We also provide a blogging service that will help your site get indexed fast and keep the search engines visiting your site. Click here for more information about turnkey pharmacy web site.
Thank you
TWP Admin

startonline said...

Your blog contained issues relating to hosting personal services web
which I found quite absorbing. I would argue that hosting personal services web
matters are best left to the professionals in most cases.

clicking4man said...

I enjoyed reading your blog. There is a lot of useful information about web hosting in it. We offer Turnkey Websites and Reliable Hosting. We also provide a blogging service that will help your site get indexed fast and keep the search engines visiting your site. Click here for more information about web hosting.
Thank you
TWP Admin

Small Business said...

This hosting canada blog is awesome.
If you get a moment you may want to visit
this hosting canada site
it's pretty awesome too!

tipsonrelationships said...

I enjoyed reading your blog. There is a lot of useful information about small business web site hosting in it. We offer Turnkey Websites and Reliable Hosting. We also provide a blogging service that will help your site get indexed fast and keep the search engines visiting your site. Click here for more information about small business web site hosting.
Thank you
TWP Admin

officialloversguide said...

I enjoyed reading your blog. There is a lot of useful information about top 10 home based business in it. We offer Turnkey Websites and Reliable Hosting. We also provide a blogging service that will help your site get indexed fast and keep the search engines visiting your site. Click here for more information about top 10 home based business.
Thank you
TWP Admin

clicking4man said...

I enjoyed reading your blog. There is a lot of useful information about affordable web hosting in it. We offer Turnkey Websites and Reliable Hosting. We also provide a blogging service that will help your site get indexed fast and keep the search engines visiting your site. Click here for more information about affordable web hosting.
Thank you
TWP Admin

Mr 666 said...

Why wouldn't you charge a customer for the time it took you to create the unit tests. You may say that the customer has no interest in the unit tests, but the fact is that an addional cost was still incurred on that customers behalf.

If our profession feels it's not right to charge for "background" costs then why is it ok for other professions to do so?

Dan Bunea said...

>>Why wouldn't you charge a >>customer for the time it took >>you to create the unit tests. >>You may say that the customer >>has no interest in the unit >>tests, but the fact is that an >>addional cost was still incurred >>on that customers behalf.

>>If our profession feels it's not >>right to charge for "background" >>costs then why is it ok for >>other professions to do so?

Hi,

We do charge our customers for the automated tests.

However the funny thing is that the client does pay for the tests and the code, but still pays less then paying just for the code.

The tests increase quality and the development speed especially when the project is growing.

Thanks for your comment,
Dan