Skip to main content

Continuous Integration with,Unit Test(Test Driven Development) and TFS

Before some time I have written a blog post about Continuous integration with and TFS and It goes quite a good number visits and lots of people are asking for unit test integration with continuous integration too. Today one of colleague also asked for the same. I thought it will be good idea to write a Blog post about it.

In this blog post we are going to create a new MVC application with a Test Project so that we can run tests and configure unit test with continuous integration. So Let’s first create a new application in visual


Once we are done with project we are going to open that project in  visual as we have done in previous post.


After mapping workspace. it’s time to create a new solution and this time we are going to create a solution with Test project like below via clicking on new in team explorer.


 Clicking on ok will create two project one for web application and another for test.


If you now check the controllers folder and Home controller Unit test it has created three test for checking views like below.


Now let’s run this all unit test via Test-> Run-> All Test menu to make sure all unit tests are working fine. It will load test explorer with all test result. So we have not change anything so everything works fine and all tests are passed.


So we are quite ready with our application. Now it’s time to create  our build definition with Unit Test integration. So for that we have to go to team explorer and click on build.


It will load build tab from where we need to create new build definition.


Clicking on new build definition will load new build definition dialog.Now we want to do continuous integration so we need to select continuous integration in trigger tab.


Now it’s time to configure Unit Test. We need to also make sure that all test are passed before deployment. So for that we need to go to process tab of build definition. Here we need to go to set fail build on Test Failure part.


That’s it we are done with configuration part. It’s time to check in code in visual and see whether everything works fine and our test executed successfully or not.


Once you click on check in it will check in code and create a build in queue.


After some time, We can same on build tab that build has completed successfully.


Now when you double click on the build in my build it will load build details. Here it will tell whether we pass all test or not. Like below.


Here you can see all the test 3 test are passed.

What will happened if unit test fail?

Now let’s change our application code in way that it will throw some exception like below.


Now let’s again check-in/commit code.


As soon as you check in code it will trigger build in queue.


Now after some time, you will see that build will fail as we have made one test fail with throwing exception in code.


Now when you double click on that build it will show summary why it’s failed.


You see same on also in build section summary tab.


That’s it. It’s very easy to setup continuous integration with Hope you like it. Stay tuned for the 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.