Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit extension

Hi All i have a question regarding NUnit Extension (2.5.10). What i am trying to do is write some additional test info to the database. For that i have created NUnit extension using Event Listeners. The problem i am experiencing is that public void TestFinished(TestResult result) method is being called twice at runtime. And my code which writes to the database is in this method and that leaves me with duplicate entries in the database. The question is: Is that the expected behaviour? Can i do something about it? The extension code is below. Thanks.

using System;
using NUnit.Core;
using NUnit.Core.Extensibility;

namespace NuinitExtension
{
[NUnitAddinAttribute(Type = ExtensionType.Core,
                     Name = "Database Addin", 
                     Description = "Writes test results to the database.")]
public class MyNunitExtension : IAddin, EventListener
{
    public bool Install(IExtensionHost host)
    {
        IExtensionPoint listeners = host.GetExtensionPoint("EventListeners");
        if (listeners == null)
            return false;

        listeners.Install(this);
        return true;
    }

    public void RunStarted(string name, int testCount){}
    public void RunFinished(TestResult result){}
    public void RunFinished(Exception exception){}
    public void TestStarted(TestName testName){}

    public void TestFinished(TestResult result)
    {
        // this is just sample data
        SqlHelper.SqlConnectAndWRiteToDatabase("test", test", 
                                               2.0, DateTime.Now);
    }

    public void SuiteStarted(TestName testName){}
    public void SuiteFinished(TestResult result){}
    public void UnhandledException(Exception exception){}
    public void TestOutput(TestOutput testOutput){}
}

}

like image 495
Igor Avatar asked Nov 13 '22 20:11

Igor


1 Answers

I have managed to fix the issue by simply removing my extension assembly from NUnit 2.5.10\bin\net-2.0\addins folder. At the moment everything works as expected but i am not sure how. I thought that you have to have the extension/addin assembly inside the addins folder. I am running tests by opening a solution via NUnit.exe. My extension project is part of the solution i am testing. I have also raised this issue with NUnit guys and got the following explanation:

Most likely, your addin was being loaded twice. In order to make it easier to test addins, NUnit searches each test assembly for addins to be loaded, in addition to searching the addins directory. Normally, when you are confident that your addin works, you should remove it from the test assembly and install it in the addins folder. This makes it available to all tests that are run using NUnit. OTOH, if you really only want the addin to apply for a certain project, then you can leave it in the test assembly and not install it as a permanent addin. http://groups.google.com/group/nunit-discuss/browse_thread/thread/c9329129fd803cb2/47672f15e7cc05d1#47672f15e7cc05d1

like image 153
Igor Avatar answered Dec 05 '22 07:12

Igor