ExpressUnit

Helgevold Consulting, LLC

RSS

XPathItUp

SeleniumHelper

How To Write Unit Tests in Visual Studio Express Using NUnit

Visual Studio Express is a scaled down version of Visual Studio. The product is available for free and can be downloaded from Microsoft. However, it has one serious short coming; it doesn’t support unit testing!

It is unfortunate that Microsoft has excluded unit testing from Visual Studio Express, but there is still hope for those of you who want to do Test Driven Development. The solution is to add a third party unit testing framework. I have looked into Nunit

To write unit tests in Visual Studio Express using Nunit follow these steps.

  1. Download Nunit
  2. Create a class library project in Visual Studio Express
  3. Add a reference to nunit.framework.dll (This file was downloaded as part of step 1)
  4. Write your test code (Add your test classes to the class library you added as part of step 2)

The test code follows the following format:


Figure1 - Sample NUnit test

It is important that you put the Test attribute on every test method and the TextFixture attribute on the class itself.

Start the Nunit GUI application and open the class project which was created as part of step 2).

Now, all you have to do is select the tests to run from the test tree on the left and press the Run button. A green bar will appear if the test(s) ran sucessfully.


Figure2 - NUnit test runner


Share
You comment has been saved. It will appear as soon as we have approved it
Please fill out all fields

Feel free to comment on this article!

Your name


Title


Your comment




Written by
Rus Davies

Date
10/4/2010 9:43:50 AM

Title
Debugging

Good stuff. But, what if I want to run an nunit test with debugging? Any ideas for that?


Written by
Torgeir Helgevold

Date
10/15/2010 6:55:31 PM

Title
Debugging NUNIT tests in Visual Studio Express

Hi Rus!
Here's an article that describes how to debug Nunit from Visual studio Express.

http://kenthall.wordpress.com/2006/09/09/debugging-nunit-test-within-c-express/

I hope this helps.
-Torgeir

Written by
Gene Osteen

Date
9/13/2011 9:39:30 PM

Title
Director of Data Engineering

Teaching myself ASP.net. I have been unable to get Web Developer Express to automatically create a test project for me even though it ask if I want to. Your solution worked just fine. Many Thanks!!

© Helgevold Consulting, LLC 2010