Sunday, February 28, 2010

NUnit templates for ASP.NET MVC 2 RC 2

Now with ASP.Net MVC 2 RC 2 out, it's time to have a working NUnit template.

I tried to use the NUnit MVC 2 templates others have made available, however, I had trouble installing them with the batch file. Once I installed it manually, the results didn't compile. I discovered it was because these were altered from the NUnit MVC 1 templates. I decided to start over from the MSTest template, modifying it for NUnit. Starting from the supplied templates will make it easier to stay in sync with the ASP.NET MVC team.

The instructions here were a start, however, I took it a step further and synchronized most of the template code with the MVC 2 template code. This gave me a really good result and is really quite workable.

Try it for yourself. Get started with the following instructions:

Download the zip file: Mvc.NUnit.Testsv2.0.zip

Copy the included "MvcApplication.NUnit.Testsv2.0.cs.zip" to "%ProgramFiles(x86)%\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\Test".
If on a x64 bit machine, then %ProgramFiles(x86)% normally equals "C:\Program Files (x86)", otherwise, it's the normal location of "C:\Program Files".

Import the correct registry file (NUnit.reg or NUnit64bit.reg) to register the new template with MVC 2.

Open the "Visual Studio 2008 Command Prompt", running as administrator. Then run "devenv /setup". Once that is done, the template should be ready to use.

These templates require NUnit 2.5 or higher. Since I don't use VB.Net, I didn't make a corresponding template, if someone would like to contribute that, please feel free.

3 comments:

  1. I have updated these templates for VS 2010. You can download them from my blog, please feel free to copy, modify and re-post.

    ReplyDelete
  2. Works great, thanks.

    You might think someone from MS would have sorted this out for us - and saved me an hour of messing around! Now that they're all about Open Source and all. But thankfully at least you've sorted it out and saved me from MSTest.

    ReplyDelete