Search code examples
unit-testingmodel-view-controllernunitgallio

Running NUnit tests with Gallio


I'm trying to write some NUnit tests for a project. I add a new Class Library to the solution. Is this the correct project type?

I added a reference:

using NunitFramework;

and added my tests.

I have Gallio installed, but I'm unsure about whether it's configured properly. I'm new to using this, and I'm hoping someone can tell me how you actually run the tests.

It was my understanding you could right click and select run all tests. Alternatively I thought you could click on the [Test] attribute and click run or debug.

Alternatively, how do I load tests into the Test Results window to run debug them?


Solution

  • Basically it's correct. Your unit test should look like this:

    using System;
    using NUnit.Framework;
    
    namespace Demo
    {
      [TestFixture]
      public class SampleTestFixture
      {
          [Test]
          public void SampleTest()
          {
             // my test here...
          }
      }
    }
    

    Compile your test project (a class library is OK) in debug mode. Now you can run your test suite within any runner that supports NUnit:

    • Any Gallio test runner (Echo, PoSh snap-in, Icarus, etc.) There is a nice tutorial explaining how to use the Gallio test runners here. The examples use MbUnit instead of NUnit, but it's all the same.
    • The built-in NUnit GUI or console runner.
    • The built-in VS test runner (interfaced by Gallio) if your version of Visual Studio includes the MS testing tools. You should be able to see your tests in the test tool window, but there is a nasty trick to make VS recognize your project as a test project if you did not create it initially as such.
    • You can also use TestDriven.Net which is lightweight and fast test runner that comes as an add-in for VS. IMHO, it's certainly the most simple and efficient way to run your unit tests directly from the VS IDE.