[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
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,
A Coder’s Life