Thursday, April 17, 2014

Test Driven Development is your friend

I have seen lots developers are not seeing benefits of Test Driven development. When you do Test Driven development there are lots of benefits. So I thought it will be good idea to write a blog post about it.

What is Test Driven Development:

As per wikipedia Test Driven Development is

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards
Kent Ben an American software engineer and creator of extreme programming rediscovered this technique. There are three main indicators of Test Driven development.

There are few steps of test driven development.
  1. Create a test that fail (Red Indicator).
  2. Write some code (Green Indicator).
  3. Test again and see whether test is passed or not? If not refactor your code until it passed test(Green Indicator).
You can find more information about Test driven development from following links.

Introduction to Test Driven Development
Test Driven Tutorial-Presentation

Test Driven Development and Microsoft.NET:

There are lots framework available for Microsoft.NET which you can use to develop your software in test driven way. Even Microsoft Visual Studio also provides Test Explorer in built to create and run test from Visual Studio itself.

Following is a complete list of Mature framework available for Test Driven Development and supported in Visual Studio itself.
  1. NUnit
  2. Xunit
  3. MS Test
You can find complete comparison of above three at following link.

Following link will give you guidelines/best practices  for Test Driven Development in Microsoft.NET World.
Guidelines for test driven development

Following are few more links that will give you head start with test driven development with Visual Studio and Microsoft.NET world.

Quick Start: Test Driven Development with Test Explorer
Walkthrough: Using TDD with ASP.NET MVC
NET TDD (Test Driven Development) by example

A great video from Scott Alen about TDD and Test driven development with ASP.NET MVC. It will be eye opener for you if you are not doing Test Driven Development.

Benefits of Test Driven Development:

Following are benefits of test driven development.
  1. It will definitely will decrease your regression testing significantly. You don’t have to worry about test while you edit or refactor your code. You just need to run code and see whether your code passes existing test or not.  You will not fear about breaking something while you add new functionality to existing functionality you need to run the existing tests to see whether your code is working fine or not.
  2. Refactoring of your code will become easier and you will not break your functionality while to refactor your code.
  3. Your architecture will be better designed due to test driven development because you know what things will be break if you make this changes.
  4. Code reviews will be easy.  The person who is reviewing your code will first look at the test created and better understands existing code with the help of test performed. You don’t have to explain each and every lines of code to him.
  5. Your code stability will increase. Because if you write code to pass test means that every bit of your code coverage is good and confirmed to pass tests written then your code will be more stable.
  6. Accountability of code will be increase. Let’s take general scenario most of the time developers does not accept that his/her code break things but when you have tests written they need to make sure that all tests are must pass and that’s why accountability of developer towards their code will increase.
  7. Better planning and estimation: Now there will be a test written for everything so you can check every bit of business logic   to pass tests. So estimation of software development and planning of that development task completion will be near to perfect.
  8. Reduce bug : With test driven development there will be very less bug because tests are written for all the scenarios and bug will be detected at the time of development only.
  9. It’s faster then righting code without test- Take scenario you have create a feature in module and deployed it to testing server where doing testers review they found x number of bugs. So you again need to fix that bugs and give them for testing and this cycle will go on and on until testers are satisfy with feature and specification. Now consider time given for deployment, publishing of code on test server as well testers time for regression testing time. You will realize that it will take more time then writing tests.
So there is myth that Test Driven Development is not for developers and it’s not developer’s friend. So what are you waiting for start Test Driven Development if you are not doing that till now!! It will definitely make you more productive and it’s your friend!!

Hope you like it. Stay tuned for more..


Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog


My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews