you're reading...

Using the listener factory in TestNG

Sometime back I stumbled into a ListenerFactory in TestNG.

I have tried hunting for information about it, but so far, here’s what I have as information about it.

A ListenerFactory is a factory for instantiating your test specific listeners. This factory can be plugged into TestNG only via the @Listeners annotation. So this means that this factory can be inserted into Test classes on a per class basis but you cannot add it via the <listeners> tag to your suite file.

The second thing that I learnt about this listener factory is that per JVM there can only exist ONE instance of a TestListener factory that can exist. I haven’t yet tried figuring out what happens when there are more than one instances of such a listener.

You begin by implementing the ITestNGListenerFactory and then you associate this class via the @Listeners annotation.

So with that limited information that I have, here’s how a sample looks like : https://gist.github.com/krmahadevan/3736157



One thought on “Using the listener factory in TestNG

  1. HI,
    Very nice..
    But what is listner and what it is for, I mean what we can do with listner and what is the need of this. It would be a big help if you can clarify things… Actually I want to implement listners.

    Posted by Amit | December 19, 2013, 1:00 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: