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 deployed template also contained a reference to a specific NUnit version even when version-specific switch for Visual Studio was set to false I now removed this version-reference.
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.
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):
12345678910111213141516171819202122232425
[TestFixture]publicclassHomeControllerTest{ [Test]publicvoidIndex(){// Arrange HomeControllercontroller=newHomeController();// Act ViewResultresult=controller.Index()asViewResult;// Assert Assert.That("Welcome to ASP.NET MVC!",Is.EqualTo(result.ViewBag.Message));} [Test]publicvoidAbout(){// Arrange HomeControllercontroller=newHomeController();// Act ViewResultresult=controller.About()asViewResult;// 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.
123456
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\MVC3\TestProjectTemplates\NUnit]"Path"="CSharp\\Test""Package"="{E0915DB0-C6DC-4BF6-AEBF-9D72308FDB81}""Template"="MvcWebApplicationNUnitTestProjectTemplatev3.0.cs.zip""TestFrameworkName"="NUnit Test"
Alongside to the updated registry entry I added an install.bat file which does the necessary steps
insert registry key
copy template archive
update Viusal Studio 2010 project template cache
It isn’t much about magic glue in it, just for completeness sake I post the batch-script:
12345678910111213141516
@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====pause
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 als the stuff (reg key, vstemplate.zip and install.bat). Feel free to download :-)