NUnit extension

Showing 1-12 of 12 messages
NUnit extension IK 7/12/11 4:19 AM
Hi All i have a question regarding NUnit Extension.

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){}
    }
}
Re: [nunit-discuss] NUnit extension charlie 7/12/11 6:30 AM
What version of NUnit are you using?

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>

Re: NUnit extension IK 7/12/11 6:43 AM
2.5.10.11092
Re: NUnit extension IK 7/12/11 6:44 AM
NUnit version is 2.5.10.11092
Re: [nunit-discuss] Re: NUnit extension charlie 7/12/11 7:55 AM
OK, I'll try to replicate the problem.

Charlie

Re: NUnit extension IK 7/12/11 8:35 AM
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. Could this be why it is
somehow working?

On Jul 12, 12:19 pm, IK <puf...@googlemail.com> wrote:
Re: [nunit-discuss] Re: NUnit extension charlie 7/12/11 1:10 PM
Hi,

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.

Charlie

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>

Re: NUnit extension IK 7/13/11 12:44 AM
Thanks a lot for the explanation, Charlie. It is much clearer now what
is happening.
Re: [nunit-discuss] Re: NUnit extension Athrun Sun 5/20/12 11:13 PM
Hi Charlie,

Could you give me a more detailed explanation of 'NUnit searches each test assembly for addins to be loaded'?

For example, I have two projects in my VS2010 solution, say, project A and project B. A is a test project(contains '[Test]' inside), B is an NUnit addin project(contains addin installer, EventListener interface implementations, etc. inside), and, A references B. Does this work? Will the addin be called?

If not, I assume you mean that I must have the various .cs files(which implements the NUnit addin) directly included in project A, rather than have them placed into a separate project and reference it in test project. Is that what you mean?

If so, another problem raised, that, when I have project C, D, E... which are also test projects, I have to include those various .cs files(which implements the NUnit addin) in each test project?
Re: [nunit-discuss] Re: NUnit extension charlie 5/21/12 1:24 AM
On Mon, May 21, 2012 at 8:13 AM, Athrun Sun <okam...@gmail.com> wrote:
>
> Hi Charlie,
>
> Could you give me a more detailed explanation of 'NUnit searches each test assembly for addins to be loaded'?
>
> For example, I have two projects in my VS2010 solution, say, project A and project B. A is a test project(contains '[Test]' inside), B is an NUnit addin project(contains addin installer, EventListener interface implementations, etc. inside), and, A references B. Does this work? Will the addin be called?

In that situation, no. B is not a test assembly.

> If not, I assume you mean that I must have the various .cs files(which implements the NUnit addin) directly included in project A, rather than have them placed into a separate project and reference it in test project. Is that what you mean?

Exactly

> If so, another problem raised, that, when I have project C, D, E... which are also test projects, I have to include those various .cs files(which implements the NUnit addin) in each test project?

This feature is provided to allow testing of extensions under
development, so it's not really a problem with needing to use the
extension in multiple assemblies. In fact, if you were to duplicate
the code in two assemblies, I imagine NUnit would try to register two
different addins, with potentially surprising results. :-)

For production use, you should install the addin in the addins folder
in the normal way. In addition, it's best not to reference the addin
assembly from your code. Although this may not always cause a problem,
it sometimes does lead to the addin being loaded twice.

Charlie
> To view this discussion on the web visit https://groups.google.com/d/msg/nunit-discuss/-/a730uESbNJUJ.
Re: [nunit-discuss] Re: NUnit extension Athrun Sun 5/21/12 11:55 PM
Thanks Charlie, I understand now.
I did more research and found out that, if I include project A, B, C, etc. in a nunit test project(say ABC.nunit), the addin implemented in project B works for all the other test projects. I suppose this explains  'NUnit searches each test assembly for addins to be loaded', even if project B contains no tests.
BTW, I'm using NUnit 2.6.0.12051.
Re: [nunit-discuss] Re: NUnit extension charlie 5/24/12 4:44 AM
Yes, this would work because NUnit loads all three as test assemblies,
even though it doesn't actually find tests in B.

charlie
> https://groups.google.com/d/msg/nunit-discuss/-/lciduHlpq7gJ.