[Update 21/04/2011]: This article is for the older versions and VWD 2008. Refer to this link for an easier and automated method of setting up NUnit and VWD: http://blogs.msdn.com/b/webdevtools/archive/2009/04/28/updated-nunit-templates-for-asp-net-mvc-1-0-rtm.aspx
G’day,
Just a quick tutorial on how to setup NUnit with Visual Web Developer 2008 Express Edition using C# ASP.NET MVC 1.0.
For my sources I used the always useful Scott Gu’s blog, http://weblogs.asp.net/scottgu/, and the information from this link http://blogs.msdn.com/webdevtools/archive/2008/05/30/asp-net-mvc-preview-3-tooling-updates.aspx
- Download and install NUnit from http://nunit.com/index.php?p=download. I grabbed the one titled NUnit-2.4.8-net-2.0.msi.
- Download the NUnit MVC Preview 3 Templates from http://blogs.msdn.com/webdevtools/archive/2008/05/30/asp-net-mvc-preview-3-tooling-updates.aspx
- Unzip and edit the file titled ‘IntallNUnitTemplatesExpress.bat’. Yes it contains a spelling mitake.
- If you have installed VWD Express into a different location then you will need to replaces all references of ‘%programfiles%’ to your location
- The last line attempts to run ‘devenv’. This needs to be changed to ‘VWDExpress’
- This will then install the templates and make the necessary changes
- Open VWD Express and start a new Web Project. After finishing this it will then ask if you would like to create a unit test project. Click Yes.
- This will then create a new VWD Express workspace with two projects. Your web application and the unit test application.
- If you have errors you may need to add a reference to the NUnit dll in your project . If you used the .msi installer, then just right-click the ‘<projectname>.Tests’ project and click Add Reference. In the pop-up, under the .Net tab locate and select ‘nunit.framework’
The project will now be set up to compile the unit tests, however there is the main issue of VWD Express not having the ability to run test functionality. The first method for now is to locate your NUnit install location, and use the GUI at \bin\nunit.exe. So…
- Run <nunit-install>\bin\nunit.exe
- Click File->Open Project and browse to your projects folder
- Select the file at <projectname>\<projectname>.Tests\<projectname>.Tests.dll
The GUI will then allow you to run your tests. Every time you rebuild the Tests project, the GUI will refresh with the newly created .dll
There may be a way to run the tests through VWD Express but I have not yet found it.
Hope it all goes well,
Cheers,
A Coder’s Life
Thank you, great article!
Here is easy way to start tests:
In test project I’ve created a class with follow Main function:
[STAThread]
static void Main(string[] args) {
NUnit.Gui.AppEntry.Main(new string[] { Assembly.GetExecutingAssembly().Location });
}
and set up it as a startup object for test project. It will run NUnit’s gui with your tests loaded.
Here’s a couple more tips:
1. You don’t need to change to last line in “IntallNUnitTemplatesExpress.bat” anymore. It’s changed in the latest download.
2. If you’re running Vista, be sure to run the .bat file in a command line with Admin privileges.
3. The default test template won’t pass by default. You need to modify the tests so that they work.
I’ll try to put a post up about this in my blog soon.
Nice, wish you had posted this a month ago when I asked a question about it on Stack Overflow. I eventually got it figured out, but I like your step-by-step article as a reference.
Here’s my Stack Overflow question: How do I add NUnit as a test framework option for ASP.NET MVC to Visual Web Developer 2008 Express?
Oh, I just realized you did post this a month ago
Guess I didn’t find it till now.
[...] Read the full article here which includes links to all the software which is free! [...]
Is there an update to this for VWD2010 using MVC 2? Pretty please
.