November 7, 2009

How do I hook my version of nUnit into the ASP.NET MVC template?

If you've been looking for a way to integrate nUnit into your ASP.NET MVC 1.0 template - that is, when you create a new ASP.NET MVC application and it asks you if you'd like to create a test project, nUnit shows up in the list along with the usual Visual Studio Unit Test option.

There are a number of longwinded ways of doing things. There's also a relatively simple way touted on the Visual Web Developer Team Blog which I'll spare you the headache of running it and finding the same problems I did (although I will provide a link here for your own amusement and/or frustration) [http://blogs.msdn.com/webdevtools/archive/2009/04/28/updated-nunit-templates-for-asp-net-mvc-1-0-rtm.aspx].

They provide a nifty little zip file that contains the template, along with a batch process (.cmd) file that is supposed to install the thing for you - both of which I had problems with. The major problems I found with it are that:

  • The cmd file doesn't work on Windows 7 - at least, not on the 64 bit version I'm running on - it fails on the SET commands... plus it's horrendously badly written with repeated lines of code all over the place.
  • The template is for a specific version of the nUnit framework, which means that the if you're running a different version of nUnit, then you've gotta fix the nUnit reference every time you create a new project.

I will admit that I can't speak for all the installations that the original script was prepared for, but I'm running:

  • Windows 7 Ultimate (x64)
  • Visual Studio 2008 Professional
  • ASP.NET MVC 1.0
  • nUnit 2.5.2.9222
You can grab the zip file containing the templates and the registration script from http://www.4shared.com/file/148112477/fe226de8/nUnitMvcTemplates.html. Just unzip it to a directory on your computer and run the file installNUnit.cmd.

If you're running Visual Studio when you run it, you will have to close and re-open the IDE once the script has completed.

No comments:

Post a Comment