Test Driven Development is Your Friend
Test Driven Development is Your Friend
Join the DZone community and get the full member experience.Join For Free
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.
- Create a test that fail (Red Indicator).
- Write some code (Green Indicator).
- Test again and see whether test is passed or not? If not refactor your code until it passed test(Green Indicator).
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.
- MS Test
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.
- 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.
- Refactoring of your code will become easier and you will not break your functionality while to refactor your code.
- Your architecture will be better designed due to test driven development because you know what things will be break if you make this changes.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Hope you like it. Stay tuned for more.
Published at DZone with permission of Jalpesh Vadgama , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.