Skip to main content

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


Popular posts from this blog

How to create Rest API(Web API) with ASP.NET Core 1.0

Recently Microsoft has released ASP.NET Core 1.0 RC2, I am getting lots of request from readers that about creating Web API. So I thought it will be a good idea to write a blog post about how to create Rest API(Web API) with ASP.NET Core 1.0.

So let’s get started via creating an ASP.NET Core 1.0 Web Application like following.

Once you click on ASP.NET Web Application, It will ask whether you need to create Web Application or Web API application. We are going to Web API so I am going to select Web API Application like following. Please note that in ASP.NET Core 1.0 there is no separate libraries or DLLs required for creating web APIs. This is just a project template.

Now once you click on OK It will create a Web API application with default values controller and program.cs.  As you know Program.cs is now starting point for the ASP.NET Core 1.0 application so It contains all the required configuration and startup items. Following is a code for that.
using System.IO; using Microsoft.Asp…

How to use migration with Entity Framework Core

Entity framework core is  the lightweight, extensible and cross-platform version of Entity Framework. Before some time, Microsoft has Released a new version of Entity Framework RC2. I have written a couple of blog post about Entity framework code first migration earlier for Entity framework 6.0. So there was a couple of request coming for writing a blog post about Entity Framework Core RC2 migration. So I thought it will be a good idea to give an overview how database migration works in Entity Framework Core RC2. This post will cover a basic scenario where we are going to create the database with existing ASP.NET Identity migration and then we are going to create a new model and have that migration applied in the database.

How to use Entity Framework Migrations: Let’s get started, To demonstrate entity framework core migrations, I am going to create a sample core web application like following.

Once we select core application it will appear the following dialog.

Now w…

Creating PDF with ASP.Net MVC and RazorPDF

Update: I have written a new blog post about better approach to create a PDF with mvc- You can find that following location.- A Better Solution to create PDF with Rotativa and ASP.NET MVC
In this post we are going to learn how we can easily create PDF from ASP.Net application with the help of Razor PDF NuGet package.

About Razor PDF:
This NuGet package is created by Al Nyveldt It internally uses ITextSharp an open source PDF convertor library. RazorPDF uses Razor View engine to create iTextXML which is in tern used to produce PDF file. You can get more information about that at below link.

Example(Creating PDF with ASP.Net MVC):
So what we are we waiting for ? Let’s create a simple example. To create example first thing we need to a create and ASP.Net MVC application.