How to capture TestFinished in NUnit 3.0 with ITestEventListener

1,959 views
Skip to first unread message

Quân Hoàng

unread,
May 24, 2016, 12:20:09 PM5/24/16
to NUnit-Discuss
Hi,

I have read https://github.com/nunit/docs/wiki/Event-Listeners but it not clear for me, and i am very appreciate if some one can give me advice for implement it. 

Charlie Poole

unread,
May 24, 2016, 12:34:42 PM5/24/16
to NUnit-Discuss
It will help us give you a useful answer if you can explain a bit more
about what you don't understand.

Basically, you need to create a class that implements
ITestEventListener, give it the Extension attribute and install the
assembly you create into your NUnit installation.

Charlie
> --
> You received this message because you are subscribed to the Google Groups
> "NUnit-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nunit-discus...@googlegroups.com.
> To post to this group, send email to nunit-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/nunit-discuss.
> For more options, visit https://groups.google.com/d/optout.

Quân Hoàng

unread,
May 24, 2016, 10:48:33 PM5/24/16
to NUnit-Discuss
Hi Charlie,

Firstly, thank you so much for quickly response. I have implements ITestEventListener, could you please guide me how to debug this and how we can setup for call OnTestEvent.
In general ideal i want to create report after each test and will generate mainly report by combine all test case report after all test is finished. 

Charlie Poole

unread,
May 25, 2016, 1:11:57 AM5/25/16
to NUnit-Discuss

Each report is in the form of an XML fragment. See docs at https://github.com/nunit/docs/wiki/Test-Result-XML-Format

I suggest you start by writing each one to a file. Then select only the events that are useful to you and extract the info you want.

Charlie

--
Message has been deleted

Quân Hoàng

unread,
May 25, 2016, 5:38:56 AM5/25/16
to NUnit-Discuss
Hi Charlie,

I have write with sample code below, and create another project and add assembly to test project, but when i run my test, i cannot see it create .txt file, could you please give me some advice in using ITestEventListener. 

 public class TestEventListner : ITestEventListener
   
{        
       
public void OnTestEvent(string report)
       
{
           
this.WriteText(report);
           
       
}      
       
private void WriteText(String result)
       
{
           
System.IO.File.WriteAllText(@"C:\Test\WriteLines2.txt", result);
       
}
   
}

Charlie Poole

unread,
May 25, 2016, 11:26:06 AM5/25/16
to NUnit-Discuss
How are you installing your extension into NUnit? The engine needs to
find it. Have you reviewed the docs on creating extensions?

Quân Hoàng

unread,
May 25, 2016, 9:14:57 PM5/25/16
to NUnit-Discuss
Hi, Charlie,

I have read document for creating extensions via https://github.com/nunit/docs/wiki/Engine-Extensibility, i have copy all required file and put it to NUnit installation (reference to Locating Addins). Could you please correct me if i have made wrong steps for installing my extension into Nuni.

Charlie Poole

unread,
May 25, 2016, 9:42:27 PM5/25/16
to NUnit-Discuss
I assume your extension is a single assembly. If you have an installed
copy of NUnit, copy that assembly to the addins directory. Edit the
.addins file in the bin directory so that it has a reference to your
assembly in the same form as the other entries there. It should be
recognized and used by NUnit. If you have further problems, you may
need to post some code.
Message has been deleted

Quân Hoàng

unread,
May 26, 2016, 3:43:19 AM5/26/16
to NUnit-Discuss
Thank you so much, i have one more question but can i run it extension via Visual Studio or it can run via nunit3-console.exe. In nunit3-console.exe it working perfect but when i tried to run in visual studio it not working. Do i need to config anything else.

Rob Prouse

unread,
May 26, 2016, 7:21:32 AM5/26/16
to NUnit-Discuss
You will need to install your extension into the NUnit Visual Studio Adapter Extension. You can likely do this manually by finding the extension in you AppData directory, but the recommended way is to make your extension a NuGet package and install it with the Adapter and Engine via NuGet. See https://github.com/nunit/nunit/tree/master/nuget/extensions for examples.

On 26 May 2016 at 03:43, Quân Hoàng <minhquan...@gmail.com> wrote:
Thank you so much, i have one more question but can i run it extension via Visual Studio or it can run via nunit3-console.exe. In nunit3-console.exe it working perfect but when i tried to run in visual studio it not working. Do i need to config anything else.

--
You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nunit-discus...@googlegroups.com.
To post to this group, send email to nunit-...@googlegroups.com.
Visit this group at https://groups.google.com/group/nunit-discuss.
For more options, visit https://groups.google.com/d/optout.



--

Rob Prouse

 

I welcome VSRE emails. Learn more at http://vsre.info/

Charlie Poole

unread,
May 26, 2016, 12:20:37 PM5/26/16
to NUnit-Discuss
I added an issue to the docs repo for creating a how-to about engine
extensions.
Message has been deleted
Message has been deleted

Quân Hoàng

unread,
May 26, 2016, 8:35:30 PM5/26/16
to NUnit-Discuss
I got this error message and could you please take a look at this ''NUnitEngineException: Unable to deduce ExtensionPoint for Type Base.TestEventListener.TestListener. Specify Path on ExtensionAttribute to resolve.'' 
I add it manually by finding the extension in my AppData, i delete ignore.addins file and install my extension into this folder(the same way i have do when run in NUnit console). When i delete my extension in nunit.engine.addins it not displayed error message.

Charlie Poole

unread,
May 26, 2016, 8:50:20 PM5/26/16
to NUnit-Discuss
Let's see the declaration of your class... just the first lines.
Message has been deleted
Message has been deleted

Quân Hoàng

unread,
May 26, 2016, 9:10:18 PM5/26/16
to NUnit-Discuss
Here is my declaration for my class
using System.Text;
using NUnit.Engine;
using NUnit.Engine.Extensibility;
namespace AutomationFrameWork.Base.TestEventListener
{
    
    [Extension]

Charlie Poole

unread,
May 27, 2016, 2:12:35 AM5/27/16
to NUnit-Discuss
It's unlikely, but I wonder if NUnit is getting confused because you
gave your class the same name as one of the Engine classes?

Except for that, it looks correct. Can you show me the addins file
that you included?

Charlie

Charlie Poole

unread,
May 27, 2016, 2:22:06 AM5/27/16
to NUnit-Discuss
Actually, I guess your addins file and installation must be correct
because of the error message you got.

NUnit should be able to deduce the extension point path, because there
is only one extension point that uses ITestEventListener. However, you
could try specifying it using the named property
Path="/NUnit/Engine/TypeExtensions/ITestEventListener" That may work
or at least give a new error message.

Charlie

Quân Hoàng

unread,
May 27, 2016, 3:10:54 AM5/27/16
to NUnit-Discuss
After change my class name and also add Path="/NUnit/Engine/TypeExtensions/ITestEventListener" i got a new error message 'NUnitEngineException: Unable to locate ExtensionPoint for Type AutomationFrameWork.Base.ReportListener.TestListener. The Path /NUnit/Engine/TypeExtensions/ITestEventListener cannot be found.'


Charlie Poole

unread,
May 27, 2016, 6:01:12 AM5/27/16
to NUnit-Discuss
I'm sorry! You can't run the extension under the NUnit3 VS adapter because the adapter uses an older version of NUnit - I think it's 3.0.1! The test listener extension point was added to NUnit later. That's why it works when you use 3.2.1 under the console runner. To do it under the adapter, you have to wait for an updated version to be released.

I apologize for not realizing this sooner!

On Fri, May 27, 2016 at 12:10 AM, Quân Hoàng <minhquan...@gmail.com> wrote:
After change my class name and also add Path="/NUnit/Engine/TypeExtensions/ITestEventListener" i got a new error message 'NUnitEngineException: Unable to locate ExtensionPoint for Type AutomationFrameWork.Base.ReportListener.TestListener. The Path /NUnit/Engine/TypeExtensions/ITestEventListener cannot be found.'

Quân Hoàng

unread,
May 27, 2016, 9:56:36 AM5/27/16
to NUnit-Discuss
Thank you so much, can i know when the new version for NUnit Test Adapter release, i need it for building my custom report in Automation. Anyway NUnit will always my first choice when do any testing on C#.

Charlie Poole

unread,
May 27, 2016, 10:01:25 AM5/27/16
to NUnit-Discuss
Hopefully, sometime in the next few weeks - but no promises!
Reply all
Reply to author
Forward
0 new messages