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