Setting up an NUnit test project in VS

Setting up a test project is not a major deal with NUnit (despite what MSTest users would have you believe).  However, when you have the memory retention of an Alzheimers-stricken goldfish, it is often a pain trying to… to… what was I trying to do again?

Oh yeah, test project!

So the easiest way is to

  1. Add a new project to your solution.  Make it a class library and name it something so it is obvious that it is a test project.  I like ProjectnameUnitTesting.
  2. Rename the default class1.cs file to indicate the target of the tests (ClassnameUnitTests.cs).
  3. Go to the Debug tab on the Properties of the ProjectnameUnitTestingproject:
    1. select Start external program and point to the nunit.exe file in the folder containing the installed NUnit application (e.g. C:\Program Files\NUnit 2.6\bin\nunit.exe)
    2. In Command line arguments enter the assembly file of the test project (ProjectnameUnitTesting.dll).  If you want the tests to run automatically add ” /run” after the assembly file name.
    3. In Working Directory enter the ProjectnameUnitTesting project’s debug bin folder.
  4. In order to allow debugging while running the NUnit GUI, add the following XML to the <configuration> element in the nunit.exe.config file (located in the same folder as nunit.exe):
        <supportedRuntime version="4.0" />

Robert Kortnik has a more detailed step-by-step (with illustrations) here.

[edit – I have decided to add a few more of the steps required to the get NUnit project running]

  1. To the ProjectnameUnitTesting project add references to
    1. the NUnit framework dll (e.g. “C:\Program Files\NUnit 2.6\bin\framework\nunit.framework.dll“).
    2. the project containing the class to be unit tested.
    3. any other required dlls and projects.
  2. Alter the ClassnameUnitTests.cs file to contain the NUnit Tests you require.
  3. Change the ProjectnameUnitTesting project to be the startup project
  4. …and execute.
  5. Additional test fixtures can be added as additional classes in the ProjectnameUnitTesting project.

2 thoughts on “Setting up an NUnit test project in VS”

    1. At this point, you have created a project in which your test cases can be written. It was not my intention to show how to write the tests, just to show how to set up the project for the test suite.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s