How to covert EventListener in Nunit2 to NUnit 3?

386 Views Asked by At

I want to add a custom test reporter to NUnit. I already did it with NUnit2, but I now need to use NUnit3. I have 2 projects in my solution 1. reporter project 2. tests project

in the test project I have a nunithook file which is hooked to the reporter project which contains NunitRegistrar.

that way I can "listen" to nunit framework events. I've updated to nunit 3.8.1 and I see that everything has changed and this soultion doesn't work anymore.

This is the implementation for both files:

using Reporter.Nunit;
using NUnit.Core.Extensibility;

namespace NunitHook
{
    [NUnitAddin(Name= "NUnitHook", Description = "NUnit Hook")]
    public class NUnitHook : NunitRegistrar
    {

    }
}

using System;
using System.IO;
using System.Linq;
using NUnit.Core.Extensibility;

namespace Reporter.Nunit
{
    [NUnitAddin(Name = "EventListnerForReport", Description = "Event listener that listens to the tests and dispatches the events to the report manager")]
    public class NunitRegistrar : IAddin
    {
        private bool registeredListeners;

        public bool Install(IExtensionHost host)
        {
            if (!registeredListeners)
            {
                if (host == null)
                {
                    throw new ArgumentNullException("host");
                }

                IExtensionPoint listeners = host.GetExtensionPoint("EventListeners");
                if (listeners == null)
                {
                    return false;
                }

                listeners.Install(new TestEventListener());
                registeredListeners = true;

                return true;
            }

            return true;
        }
    }
}

is there a easy way to convert it to nunit 3?

thanks !

0

There are 0 best solutions below