Nov 17

I recently downloaded ASP.NET MVC 2.0 Preview 2 and was surprised to see, that the NUnit test templates haven’t made it into the build. Again we are stuck with MSUnit being the only template available.

msunit

Fear not help is at hand Joe Cartano posted an excellent solution for MVC 1.0.  I have made a minor one line tweak (in NUnit.reg) to his solution, so that it works with MVC 2.0.  After reading some of the comments on the Visual Web Developer Team Blog, it was apparent that some people are having issues installing the templates, here is a very quick guide:

  1. Download the tweaked NUnit Templates using the link below
  2. Ensure you close all instances of Visual Studio
  3. Ensure that you are using an account that has local administrative privileges (or use run as), then open installNUnit.cmd
  4. Wait for all the command windows to close, this may take a couple of minutes
  5. Open Visual Studio and create a new MVC 2 project – now you should be able to select NUnit as your unit test project

NewProject

NewMVC2Project

nunit

You can download the version tweaked for MVC 2 using the link below:

Download NUnitTemplatesMVC2.0.zip

Happy testing!

14 Responses to “NUnit Templates for ASP.NET MVC 2 Preview 2”

  1. DalSoft says:

    Updated today to work with the latest version of NUnit (2.5.2).

  2. developer says:

    thanx, very interesting

  3. Peter Zak says:

    It’s great to see the example AccountController with NUnit test. Thanks.

  4. Nathan Brown says:

    I had some problems using this template, so I went back to the ASP.Net MVC 2 RC 2 test template and modified it for NUnit. Check it out here: NUnit templates for ASP.NET MVC 2 RC 2

  5. Sergio says:

    What about Visual Web Developer? I tried using your quick guide but… it doesn’t work…

    • DalSoft says:

      I’m in the process of updating the code for the official MVC 2 release. Not promising anything, but if I can get it working with Visual Web Developer Express I’ll post it here.

  6. Alexandra says:

    Any luck with Visual Web Developer Express, MVC 2 and NUnit?

  7. Krokonoster says:

    Hi,
    Nice work and thanks for sharing. However things are not working out that well over here:
    Using VS 2k8 SP1 (Team System) and MVC 2.
    Followed your steps exactly, and indeed I had nUnit as option in the “Create a Test Project” screen.
    However, when selecting nUnit, the project get created without a test project.
    A [project].test are created in my solution directory, but it’s empty.
    Any advice?
    Krok

  8. Rush says:

    Hello, is there any update of a template for Visual Web Developer Express 2010 ?

    Thanks.

  9. [...] testing MVC 2 projects. How to: Add a Custom MVC Test Framework in Visual Studio and a post about NUnit Template for ASP.NET MVC 2 [...]

  10. mvcmax says:

    I am using vwdExpress Sp1 with MVC2. I followed your instructions (replacing the MVC registry key name in the NUnitExpress.reg file with MVC2). Now when i create an MVC2 Web Application project, the “Create Unit Test Project” Dialog box pops up, but when I click on the OK button , the window closes but the test project is nowhere to be found. Help!!

Leave a Reply

preload preload preload