Update [2011-04-03]:

Time for another update: The extension is is of today hosted on Visual Studio Gallery. Read ASP.NET MVC NUnit test template on Visual Studio Gallery for further information.

Update [2011-01-22]:

Meanwhile ASP.NET MVC 3 RTM has arrived - this template is still good to go even for RTM version. As you can see in the comments I initially forgotten to explicitly mention that the originally template was x64 only. As an result I tried to change the .bat file accordingly to handle x86 platforms as well. So when you download the newly packed template this should determine if your system is x86 or x64 and call the proper files for installing the template correctly.

The first template also contains a reference to a specific NUnit version even when version-specific switch for Visual Studio was set to false I removed this version-reference.

As most of you may have read in the meanwhile on December, 10. ASP.NET MVC 3 RC 2 was released. (you can read the announcements over @ ScottGu’s Blog or you’ve been haacked)

What ships with that release again is the possibility to create new test- projects (according to a new created projects), from the build-in project templates, which does use the Microsoft unit-testing framework (in the wizard called Visual Studio Unit Test). This isn’t anything new!


Based on Piotr’s MVC 2 test-project template I updated it (based on the shipped MvcWebApplicationTestProjectTemplatev3.0.cs.zip) to be compatible with ASP.NET MVC 3 (RC2) and changed the notation to Assert.That(…, Is-constraint) - which I prefer while using NUnit. So the vstemplate looks like this now:

Visual Studio NUnit Template
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<Name Package="{E0915DB0-C6DC-4BF6-AEBF-9D72308FDB81}"/>
<Description Package="{E0915DB0-C6DC-4BF6-AEBF-9D72308FDB81}"/>
<Icon Package="{52CBD135-1F97-2580-011F-C7CD052E44DE}" ID="531"/>
<CustomParameter Name="$MVCReferences$" Value="System.Web.Mvc.dll"/>
<Project File="MvcApplicationTest.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="App.config">App.config</ProjectItem>
<Folder Name="Controllers" TargetFolderName="Controllers">
<ProjectItem ReplaceParameters="true" TargetFileName="HomeControllerTest.cs">HomeControllerTest.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="AccountControllerTest.cs">AccountControllerTest.cs</ProjectItem>
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>

If you compare it to the old MVC 2 template you will probably notice that the extension wizard is gone. Don’t know why - maybe we should ask @haacked about that…

A sample of the generated NUnit-Tests (as of the HomeController):

generated NUnit test
public class HomeControllerTest
public void Index()
// Arrange
HomeController controller = new HomeController();
// Act
ViewResult result = controller.Index() as ViewResult;
// Assert
Assert.That("Welcome to ASP.NET MVC!", Is.EqualTo(result.ViewBag.Message));
public void About()
// Arrange
HomeController controller = new HomeController();
// Act
ViewResult result = controller.About() as ViewResult;
// Assert
Assert.That(result, Is.Not.Null);

To use the new template you still need a registry key referring to the new package. The one I used is only x64 compatible. Remember: The GUID’s of the vstemplate and the registry need to match.

registry key
Windows Registry Editor Version 5.00
"TestFrameworkName"="NUnit Test"

Alongside to the updated registry entry I added an install.bat file which does the necessary steps

  1. insert registry key
  2. copy template archive
  3. update Visual Studio 2010 project template cache

It isn’t much about magic glue in it, just for completeness sake I post the batch-script:

@echo off
echo ==== Installing ASP.NET MVC 3 NUnit project template ====
echo Updating registry settings [X64]
regedit /s MvcWebApplicationNUnitTestProjectTemplate.reg
echo Copying MvcWebApplicationNUnitTestProjectTemplatev3.0.cs.zip to Visual Studio 2010 project templates folder
xcopy .\MvcWebApplicationNUnitTestProjectTemplatev3.0.cs.zip "C:\Program Files(x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Test" /Y /I
echo Updating Visual Studio 2010 project template cache
"C:\Program Files(x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /setup
echo ==== Done ====

After executing the install.bat and creating a new ASP.NET MVC 3 application the project template should show up as following:


I packed an archive containing all the stuff (reg key, vstemplate.zip and install.bat). Feel free to download :-)

Happy unit-testing!