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.
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:
- Download the tweaked NUnit Templates using the link below
- Ensure you close all instances of Visual Studio
- Ensure that you are using an account that has local administrative privileges (or use run as), then open installNUnit.cmd
- Wait for all the command windows to close, this may take a couple of minutes
- Open Visual Studio and create a new MVC 2 project – now you should be able to select NUnit as your unit test project
You can download the version tweaked for MVC 2 using the link below:
Download NUnitTemplatesMVC2.0.zip
Happy testing!
This also works with ASP.NET MVC 2 Beta
Updated today to work with the latest version of NUnit (2.5.2).
thanx, very interesting
It’s great to see the example AccountController with NUnit test. Thanks.
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
Sorry to hear it’s not working for you, I think they have changed the AccountController in ASP.NET MVC 2 (Release Candidate 2) . Will check out your post, I’ll also will be upgrading my example soon.
What about Visual Web Developer? I tried using your quick guide but… it doesn’t work…
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.
Any luck with Visual Web Developer Express, MVC 2 and NUnit?
Sorry I haven’t had a chance yet, been spending all my spare time writing a massive post on MVC 2 templates.
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
Hello, is there any update of a template for Visual Web Developer Express 2010 ?
Thanks.
[…] 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 […]
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!!