This is a quick overview to get Nunit running. One can get Nunit here.

Here are the steps to get going with NUnit:

  1. Install Nunit to your computer.
  2. Create a Library Assembly, specifically to hold nunit tests, and add it to your solution.
  3. Working in that library, reference the Nunit Framwork and your assemblies that you want to test.
  4. For that assembly project only change the Debug setting found in Start Action to Start External Program. Browse to the nunit-gui.exe.
  5. Setup a class which looks like this:
  6. using System;
    using System.Collections.Generic;
    using System.Text;
    
    
    using NUnit.Framework; // Add the Nunit Framework reference to the project.
    
    
    
    
    // Replace the *xxx* with appropriate names that mean sense to you.
    namespace *TestSet*
    {
    
    
        [TestFixture]
        public class TestSubTests
        {
    
    
            [TestFixtureSetUp]
            public void Init()
            {
                // (Optional): Setup any common test variables. 
                // This is called once before all tests. 
                // Do not put any tests/asserts here.
    
    
            }
    
    
            [Test]
            public void *ActualTest*()
            {
                // Call the Assert.X methods to test items.
            }
    
    
        }
    
    
    }
    
    
  7. Access your in the test method and initialize/create your class. Put in Asserts such as these which will check for null objects:
  8. 
    
    Assert.IsNotNull(myXml, "Xml not loaded");
    Assert.IsNotNull(UserSettings, "User Settings Failure");

There are other asserts which are found by intellisense. Also as a suggestion, put in Console.Writline calls to give a status as operations commence and view them in the display.

  1. Debug the your testing library and the gui will come up (See step 2). It will start with a blank project. Choose Project->Add Assembly and choose test assembly you have just created. Once that is done Nunit will reflect into the assembly, finding your test class(es) and present them to you in the tree view.
  2. Save the project.
  3. Run all tests by choosing the parent nodes or an individual test method. If the an assert catches, a red bar will be shown or if an unhandled exception will cause a test to fail. Otherwise it will be green and one can look at Console.Out tab for information presented by the Console writes. In your test classes override ToString to print out status of the object. That will allow you to print out information to Nunit to debug.

I use Nunit and require anyone who gives me code to give me nunit tests. It allows me to come up to speed on someone else’s code quite quickly. It also allows me to have a suite of tests which if I change something, my tests will me more apt to pick up the failure than a tester later on down the line. Well worth the extra effort in setting it up.

Share