views:

4556

answers:

7
  • I have nUnit installed.
  • I have VS2008 Team Edition installed.
  • I have ASP.Net MVC Preview 4 (Codeplex) installed.

How do I make Visual Studio show me nUnit as a testing framework when creating a new MVC project? At this point I still only have the Microsoft Testing Framework as a choice.

Update: I installed nUnit 2.5, but still with no success. From what I've found Googling, it would seem I need to create templates for the test projects in order for them to be displayed in the "Create Unit Test Project". I would have thought that templates be readily available for nUnit, xUnit, MBUnit, et. al. Also, it looks like I need to created registry entries. Anybody have any additional information?

Update: I determined the answer to this through research and it's posted below.

A: 

Do install Testdriven.net to integrate NUnit with Visual Studio. MbUnit and later versions of NUnit also contain project templates for unit tests.

You can use those project templates to create a test project and then reference to your ASP.NET MVC project and be able to test its code.

Jon Limjap
+2  A: 

@Peter Meyer - What version of nUnit did you install? The nUnit 2.5 Alpha 3 release contains the VS 2008 project templates needed to get nUnit as an option in the Create Unit Test Project dialog that shows up after choosing the ASP.NET MVC Application template.

@Jon Limjap - When creating a ASP.NET MVC application, it gives you an option to create a unit test project at the same time. Please check this link out to see a screen shot of the dialog that is presented to you after choosing the ASP.NET MVC Web Application and clicking OK. This is what Peter is asking about.

Dale Ragan
A: 

@Dale - Yes, that's exactly what I'm talking about. I installed 2.4.8 -- I will give the alpha version a shot.

Update: Version 2.5 Aplha 3 of nUnit does not seem to contain test project templates either.

Peter Meyer
+16  A: 

After a bunch of research and experimentation, I've found the answer.

  • For the record, the current release of nUnit 2.5 Alpha does not seem to contain templates for test projects in Visual Studio 2008.
  • I followed the directions here which describe how to create your own project templates and then add appropriate registry entries that allow your templates to appear in the drop-down box in the Create Unit Test Project dialog box of an MVC project.

From a high level, what you have to do is:

  1. Create a project
  2. Export it as a template (which results in a single ZIP archive)
  3. Copy it from the local user's template folder to the Visual Studio main template test folder
  4. Execute devenv.exe /setup
  5. Run regedit and create a few registry entries.

So much for the testing framework selection being easy! Although, to be fair MVC is not even beta yet.

After all that, I did get the framework of choice (NUnit) to show up in the drop down box. However, there was still a bit left to be desired:

  • Although the test project gets properly created, it did not automatically have a project reference to the main MVC project. When using Visual Studio Unit Test as the test project, it automatically does this.
  • I tried to open the ZIP file produced and edit the MyTemplate.vssettings file as well as the .csproj project file in order to correct the aforementioned issue as well as tweak the names of things so they'd appear more user friendly. This for some reason does not work. The ZIP file produced can not be updated via WinZip or Win-Rar -- each indicates the archive is corrupt. Each can extract the contents, though. So, I tried updating the extracted files and then recreating the ZIP file. Visual Studio did not like it.

So, I should probably read this as well which discusses making project templates for Visual Studio (also referenced in the blog post I linked to above.) I admit to being disappointed though; from all the talk about MVC playing well with other testing frameworks, etc, I thought that it'd be easier to register a 3rd party framework.

Peter Meyer
voted up; thank you for this!
George Stocker
+1  A: 

Man, they have VS 2008 project template listed in their release notes. I guess that doesn't mean they have it integrated with the dialog yet.

I use MbUnit with Gallio and everything worked like a charm. I had to install an Alpha of Gallio and MbUnit and when I read the above in the release notes, I figured they implemented it also.

Just keep a look out on nUnit's site for future alpha releases. I am sure they'll have it implemented soon. You could also implement the feature yourself and submit a patch. :-)

Dale Ragan
A: 

@Dale - I tried MbUnit with Gallio, and it did indeed work like a charm. Yeah, I read the same release notes as you -- a couple times over because I figured I must be missing something! :-P Anyway, good point -- I could submit a patch. I was thinking along those lines. I am going to try to get the templates working tonight, so maybe I will do just that. The ZIP archive thing is real strange -- according to MS documentation for Visual Studio templates, they specify to do a right click and send to compressed folder ... -- i.e. their compression. So maybe their stuff is a bit different. I'll post any updates here. Thanks for all your insight.

Peter Meyer
+1  A: 

Although they do not have one bundled with the framework here is a link to post containing a download to automatically create the test project for "NUnit with moq" for you NUnit with Moq

(did not work right away on my computer, W7 Beta, make sure you use elevated permissions)

smaclell
Thanks for the resource as this is still an issue. I'm a bit surprised that the the MVC team didn't provide some sort of easier mechanism to choose the unit testing framework you'd like.
Peter Meyer