Thursday, September 18, 2008

Simple nunit walkthrough

To setup a nunit test do the following.

1. Download and install nunit 2.0
2. In your VS project add a reference to nunit.framework
3. In your VS project create a new class. Name doesn't matter.
4. Add using NUnit.Framework to your using statements for the new class
5. Prefix your new class with [TestFixture]. example [TestFixture] public class MyTest{}
6. Prefix a method to setup your class with [SetUp]. example: [SetUp] protected void setup() {}
7. Prefix your test methods with [Test]. example [Test] public void ThisIsATest() {}
8. In your ThisIsATest() method type Assert. (PS type Assert dot so you can see the auto-complete)
And then look at the list of options available to you. Each test method should have one assert method which does a test.

To run the test, first build your project, then find nunit on your start menu and open it up. Use it to browse for the dll or exe in your bin folder you just compiled.
Use NUnit to run the test.

NUnit will look for the classes in your project prefixed with [TestFixture] and execute all the [Test]s in it. It will then show you a summary of the results.

Thats all there is to it

No comments: