TestRunner for Visual Studio 2005 Manual

Getting Started

TestRunner assumes you know a bit about NUnit, but if you don't, all that is required to get started is knowing about Test Fixtures and Tests. Test Fixtures are public types -- classes -- that contain Tests, which are public, no argument methods. These are decorated with the [TestFixture] and [Test] attributes so NUnit will know to load them.

To quickly see what Test Runner can do, create a new, empty C# Class Library Project. It should contain a file Class1.cs unless you have changed you local template.

Setting Up TestRunner

TestRunner has a set of tool windows that allow you to visualize tests much like NUnit-Gui. You get at these from the Visual Studio menu Tools | TestRunner. This will launch the main, empty TestRunner window.

If you are familiar with NUnit, you know that you must reference nunit.framework.dll from your project in order to declare tests. If you keep a certain build of NUnit that you prefer, reference it now, or allow TestRunner to do it for you by going to the TestRunner window that we just opened and clicking on it's menu Options | Fix NUnit References, which will have your project reference the NUnit bundled with TestRunner.

Making Tests

For this example we'll make a test that doesn't really test any of our code, it just exercises NUnit. In Class, mark it with [TestFixture] and make a single [Test] method. Inside SimpleTest, we'll just make a basic assertion that true is, well, true. Normally, you would put code here that calls your own, asserting that pre and post conditions are as you would expect them, verifying your code is correct, but for now, we're just focused on how to work with TestRunner. Here is the code:

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace ClassLibrary1 {
    [TestFixture]
    public class Class1 {
        [Test]
        public void SimpleTest() {
            Assert.IsTrue(true);
        }
    }
}

        

Now, compile your project. By default, when you have successfully compiled, TestRunner will look through your solution for tests and load the TestRunner window. It Should look like this:

Now you can run all your tests by pressing the Run Tests button, shaped like a green arrow. You'll need to expand the Class1 test fixture in the tool window to see the SimpleTest case in the tree. By default TestRunner expands down to TestFixtures to keep the screen less cluttered. The tool window does remember your expansion settings in a Visual Studio session.

TestRunner will also update your Visual Studio editor with the test run results, code coverage, and performance metrics by default. All of these are options and can be individually disabled or customized if you like. Coverage and Performance are described in other sections of the manuals.

The large green ball indicates that your test has passed. The stacked green markers in the far left gutter area indicate code coverage. The thin green stripe just inside the editor, by the ball indicate that the test case was run, and that it passed. All of the markers are configurable, you can change the colors, and whether they appear in the Tools | Options | TestRunner panel in Visual Studio.

Recap

That's it. If you know NUnit, you know enough to get started. The rest of the manual dives into each feature in detail.