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
DEFAULT CREATED UNITTEST.CS FILE
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace WebApplicationTest { [TestClass] public class UnitTest1 { [TestMethod] 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: 10917 | Post Order: 132