ASP.NET MVC > Unit testing

Create new ASP.NET MVC Test project in ASP.NET MVC

How to create a new ASP.NET MVC Test project?

To create a new ASP.NET MVC Test project, right click the solution and select Add > New Project ….

Select Visual C# > Test > Unit Test Project as displayed below

Add the reference of the Web Application for which we need to write the Unit test by right clicking the Unit test project and clicking on References > Add Reference ….

Add an App.Config file into the project

After following above steps our basic infrastructure of the Test project is ready and it looks something like below.

By default, the Test project creates a UnitTest.cs file that looks like below


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace WebApplicationTest
    public class UnitTest1
        public void TestMethod1()


To mark a class file as a Test class, we need to decorate the class with [TestClass] attribute. To mark a method as Test method, we need to decorate the method as [TestMethod]. Both TestClass and TestMethod exists into Microsoft.VisualStudio.TestTools.UnitTesting namespace.

 Views: 1698 | Post Order: 132

Write for us