DevOps Zone is brought to you in partnership with:

I am former Microsoft MVP for Visual C# having 9 Year of experience in Microsoft.NET And other Microsoft Technologies. Please fill free to contact me at www.dotnetjalps.com Jalpesh is a DZone MVB and is not an employee of DZone and has posted 60 posts at DZone. You can read more from them at their website. View Full User Profile

Test Driven Development is Your Friend

04.18.2014
| 5082 views |
  • submit to reddit

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.
TDDDotNetJalps
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.

WikiPedia-Test-driven_development
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.
http://xunit.codeplex.com/wikipage?title=Comparisons&referringTitle=Home

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.http://pluralsight.com/training/Player?author=scott-allen&name=mvc4-building-m9-tests&mode=live&clip=0&course=mvc4-building

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.

 

Published at DZone with permission of Jalpesh Vadgama, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)