Welcome to MSDN Blogs Sign in | Join | Help

Visual Web Developer Team Blog

Your official information source from the Visual Web Developer team.

News

  • These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified Terms of Use
Updated NUnit Templates for ASP.Net MVC 1.0 RTM

ASP.Net MVC 1.0 RTM has been out for a while and I noticed that people are still downloading an NUnit sample project I created for ASP.Net MVC Preview 3. Since then an AccountController class and a corresponding set of unit tests have been added to the MVC Application project. I created an updated set of NUnit templates with tests for the Home and Account controllers. To install the templates, just extract the zip file from the link below and run installNUnit.cmd. VWD Express is supported along with VSTS as well as support for x86 and x64 bit OS's. If you are installing on Vista or higher, run the cmd file as an admin.

NUnit Test Templates 

Below is a screenshot of the NUnit AccountControllerTest class for Visual Basic. If you build a new MVC project with NUnit selected as the test framework and run the test project dll in NUnit, you will see all the tests pass.

 NunitRTM

Hope this helps you unit test your MVC Apps!

Joe Cartano | Visual Web Developer

Posted: Tuesday, April 28, 2009 11:59 AM by WebDevTools

Comments

What's New said:

ASP.Net MVC 1.0 RTM has been out for a while and I noticed that people are still downloading an NUnit

# April 29, 2009 4:47 PM

Ran Davidovitz said:

Great, i was looking for this yesterday

# April 29, 2009 4:54 PM

Mike Henry said:

Sweet! This makes life much easier than trying to manually set up the templates. This is a better solution to my <a href="http://stackoverflow.com/questions/666941/how-do-i-add-nunit-as-a-test-framework-option-for-asp-net-mvc-to-visual-web-devel/805276">Stack Overflow question</a>.

# April 29, 2009 11:53 PM

Visual Web Developer Team Blog said:

Note: Please see this post for an updated set of templates created for ASP.NET MVC RTM: http://blogs.msdn.com/webdevtools/archive/2009/04/28/updated-nunit-templates-for-asp-net-mvc-1-0-rtm.aspx

# May 4, 2009 11:38 AM

Sam said:

I'd like to add that I needed to restart my machine after applying this in order for the dialog to appear.

# May 11, 2009 2:47 PM

WebDevTools said:

@ Sam

Sam, was VS running while you installed? This might have affected the command to reset VS. If not, please let me know and I'll take a look on express(?) to see what might be going wrong.

Thanks,

Joe

# May 11, 2009 3:52 PM

womp said:

Oh my god... I ran your script and now when I start Visual Studio it says "No templates can be found"... agh!

# May 12, 2009 2:15 AM

womp said:

Okay... I managed to fix it by booting up a visual studio command prompt and typing "devenv /installvstemplates"... and now the NUnit MVC templates are available as well... so looks like success.

But what a scare.

# May 12, 2009 2:23 AM

WebDevTools said:

@womp

Hi womp, can you please send me mail at joecar at microsoft dot com? I would really like to investigate what happened in your case. The script copies two templates, sets an mvc specific reg key, and then runs devenv /setup so I was surprised to hear about this and would like to find out more about what happened.

Thanks,

Joe

# May 12, 2009 11:57 AM

Jack Whitney said:

The installNUnit.cmd didn't work for me without some help.

The :express block makes the Test directories.

mkdir "%DevEnvDir%\ProjectTemplates\VisualBasic\Test"

mkdir "%DevEnvDir%\ProjectTemplates\CSharp\Test"

The :vsts block doesn't make the Test directories. I'm running Visual Studio Standard Edition. The :vsts block was triggered, but there were no Test directories. I manually created the Test directories and then it worked.

# May 13, 2009 3:28 PM

joecar said:

@Jack,

Thanks for the catch. I'll take a look and see if I can create the test directories for STD as well as Express.

# May 13, 2009 5:48 PM

t800t8 said:

The installer doesn't work on Win 7 RC. When I try to merge NUnit64bit.reg to the registry, it creates "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Wow6432Node\Microsoft\VisualStudio\9.0\MVC\TestProjectTemplates\NUnit\C#" node (note: "Wow6432Node\Wow6432Node")

# May 27, 2009 10:46 AM

ScottGu's Blog said:

Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

# May 30, 2009 6:40 PM

BusinessRx Reading List said:

Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

# May 30, 2009 6:47 PM

Microsoft and DiscountASP.NET news said:

Some good stuff: (Thanks Scott) May 30th Links: ASP.NET, AJAX, ASP.NET MVC, Visual Studio Here is the

# May 30, 2009 7:44 PM

ASP.NET Chinese Blogs said:

【原文地址】 May 30th Links: ASP.NET, AJAX, ASP.NET MVC, Visual Studio 【原文发表日期】 Saturday, May 30, 2009 3:39

# May 31, 2009 9:46 PM

Joe Cartano said:

@t800t8,

I am not sure how that happened, here is the reg info, I'll try this out on Win7 x64 to see if I can find what the problem might be:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\MVC\TestProjectTemplates\NUnitDemo3\C#]

"Template"="MvcApplication.NUnit.Tests.zip"

"Path"="CSharp\\Test"

"TestFrameworkName"="NUnit"

"AdditionalInfo"="http://www.nunit.org/index.php?p=home"

"Package"="{DC519505-FBF8-48c7-AAA5-F27B0405F278}"

# June 3, 2009 1:06 PM

Блог Скотта Гатри (перевод) said:

Вот последняя статья из моей серии списка ссылок . Также обратитесь к моим страничкам Советы, секреты

# June 15, 2009 11:25 AM

AntiAliasing said:

Error with Vista X64 and VS 2008 Express, looks like there is an issue what a path. This is what I get when I try to execute installNUnit.cmd (as Administrator):

c:\NUnitRTM>installNUnit.cmd

c:\NUnitRTM>setlocal

c:\NUnitRTM>Set CopyFrom=c:\NUnitRTM\

\Microsoft was unexpected at this time.

c:\NUnitRTM>            Set DevEnvDir=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\VWDExpress

# June 15, 2009 5:38 PM

Adil Faisal said:

I was running the installNUnit.cmd from the VS2005 command shell. THat makes it choose wrong DevEnvDir (i.e. it chooses VS2005 as the IDE rather than the VWD). Running the script from regular cmd prompt solved the problem.

# June 18, 2009 4:11 PM

Digging My Blog - Dan Hounshell said:

There are much longer more detailed ways involving editing the registry, running "devenv ..." command

# June 19, 2009 11:50 PM

The Complete Dan Hounshell said:

There are much longer more detailed ways involving editing the registry, running "devenv ..." command

# June 20, 2009 12:22 AM

Michel said:

Does this template is still valid with the ASP.NET MVC 1.0 release ?

# July 17, 2009 4:42 AM

Michael said:

I am having no luck getting this installed on Windows XP and Visual Studio 2008 Standard.  I downloaded and installed NUnit 2.5.1.  Then I ran NUnit Test Template installer above.  Then I rebooted, opened Visual Studio 2008, created a new MVC Project, and no unit test dialog appeared.   No errors appeared during any installation.

Anyone have any ideas?  It doesn't seem like it should be this hard.

# July 23, 2009 4:03 PM

Michael said:

Apparently, if you don't have a Test directory present in

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp and VisualBasic

...it won't properly copy the zip file (just creates a Test file with nothing in it and no extension).

I hope this saves someone else a lot of frustration.

Michael

# July 23, 2009 4:42 PM

joecar said:

Hi Michael,

Thank you for pointing this out. I just uploaded a fix for this issue so that the test directory will be created if it does not exist already. I was doing this for Express but now I do this for all skus. If anybody else has trouble with installing on the STD sku, feel free to ping me at joecar at microsoft dot com.

# July 23, 2009 6:09 PM

Ryon Day said:

Installed this and I can make a test project, but it seems to have a faulty link to 'nunit.framework' (there is a yellow exclamation mark warning sign next to it). I have NUnit installed, but perhaps not in the directory expected by these templates? Where is it supposed to be?

# July 25, 2009 6:52 PM

Ryon Day said:

So after some investigation, I appear to have fixed this. I had the newest version of NUnit downloaded, and searched for 'nunit' in the project definition, and found this:

<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />

I replaced this with an analogous nunit reference in a project in which I had set up the reference myself:

<Reference Include="nunit.framework, Version=2.5.1.9189, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />

I had to replace the references in the template directory as well as the template cache directory (this was key). The question being is whether or not I have to change the reference again every time I upgrade nunit versions. Would changing the reference declaration to something like

<Reference Include="nunit.framework />

work as well?

# July 25, 2009 7:39 PM
New Comments to this post are disabled
Page view tracker