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
- 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.
- Rename the default class1.cs file to indicate the target of the tests (ClassnameUnitTests.cs).
- Go to the Debug tab on the Properties of the ProjectnameUnitTestingproject:
- 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)
- 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.
- In Working Directory enter the ProjectnameUnitTesting project’s debug bin folder.
- 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):
<startup> <supportedRuntime version="4.0" /> </startup>
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]
- To the ProjectnameUnitTesting project add references to
- the NUnit framework dll (e.g. “C:\Program Files\NUnit 2.6\bin\framework\nunit.framework.dll“).
- the project containing the class to be unit tested.
- any other required dlls and projects.
- Alter the ClassnameUnitTests.cs file to contain the NUnit Tests you require.
- Change the ProjectnameUnitTesting project to be the startup project
- …and execute.
- Additional test fixtures can be added as additional classes in the ProjectnameUnitTesting project.
Bene, e poi?
LikeLike
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.
LikeLike