My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
NUnitRunThrough  
A Quick Run Through of the NUnit TestLink Adapter.
Featured
Updated Nov 25, 2009 by StephanMeyn

What is the NUnit TestLink Adapter?

The test link adapter is an Addin for the NUnit unit testing framework. It exports test results into Testlink, which is a test management application.

Introduction

To make use of the NUnit TestLink Adapter (NTA), you must first add a new attribute to each TestFixture. This attribute, called TestLinkFixture takes parameters that tell the adapter where to find the test cases to record results to. Typically the tests are run as part of a build script or a batch file. The NTA is an extension to the command line runner. When the tests have been run, the extension is called with the test results. The extension parses the results, loads the test assemblies that have been run and extracts the test link fixture. It then contacts Testlink to look for test cases with the same name as they test methods in the unit test. If the test case does not exist, NTA will create them and assign them to the Testplan. It then records the test result against that test case.

Installation

Run Time Files

Copy all the DLLs into the AddIn directory of the NUnit folder:

Invocation

In this example the console runner is used:

Nunit-Console.exe [unitTestAssembly]

TestLink Setup

In order for this to work you need to have in testlink:

  1. Enabled the API (see installation manual)
  2. Created an account for testing
  3. Created an ApiKey for this account
  4. Setup a test project
  5. Set up test suite(s) (top level test suite) for the test cases
  6. In the test project set up a test plan
  7. Optionally created test cases in the test suite and assigned to the test plan
  8. Have an active build defined in the testplan

Step 7 really is optionally because:

  1. You must make sure you name the test cases exactly as they are defined in your unit tests
  2. If you use advanced features such as contract verifiers and row tests in MBUnit you have to guess what these test cases will be named because they are dynamically generated
  3. If you don’t create test cases, NTA will do it for you – much easier

Unit Test setup

Write your test cases as you are used to. Then have the project reference TestLinkFixture.dll and add a Using Statement for it. Add the TestLinkFixture to your testfixture. The parameters are:

  • URL of the TestLink Api
  • UserName under which the test cases are authored
  • An ApiKey (provided by the testlink application)
  • The test project name
  • The test plan in the test project
  • The test suite name that will contain the test cases

Example

using NUnit.Framework;
using Meyn.TestLink;

namespace NunitAddOnSampleTests
{
    [TestFixture]
    [TestLinkFixture(
        Url = "http://localhost/testlink/lib/api/xmlrpc.php",
        ProjectName = "TestLinkApi",
        UserId = "admin",
        TestPlan = "Automatic Testing",
        TestSuite = "nunitAddOnSampleTests",
        DevKey = "ae28ffa45712a041fa0b31dfacb75e29")]
    public class SampleFixture
    {
        [Test]
        public void Test2Succeed()
        {
            Assert.IsTrue(true);
        }
    }
}

Voila. This will create a test case named Test2Succeed and record test case result against it.

Limitations

This has been tested with NUnit V 2.5.2 & C# and Testlink V 1.8.2

It should work with VB.NET.

You use this code at your own risk.


Sign in to add a comment
Powered by Google Project Hosting