Eclipse & IConfigurationListener2

47 views
Skip to first unread message

jmcgrail

unread,
Nov 8, 2016, 11:51:58 AM11/8/16
to testng-users
Hi,

I have a simple IConfigurationListener2 implementation.  I've included it in META-INF/services/org.testng.ITestNGListener.  When I run tests from the command line, the Listener is properly invoked.  When I run tests from eclipse the listener is not invoked.  Other listeners (particularly, I have an IExecutionListener and ITestListener) listed in the services file are invoked as I expect from within Eclipse.

Does this sound familiar to anyone?

I've only peripherally perused the TestNG core code a few times so I'm not really sure how the service stuff is plugged in or I'd poke around the code.

With the attached code, I only see onExecutionStart and onExecutionFinish getting invoked from with eclipse.

Thanks,
John
PS I presume the eclipse plugin is messing with the listeners.  If someone can direct me to where in the code, I can poke and perhaps submit a patch.  Assuming it's a plugin issue.
PPS The astute amongst you will recognize the attached code is actually Groovy.  Converting to straight java would be easy but I'm lazy.

My services file:
# why this not loading in eclipse??
com
.company.qa.testngListeners.ConfigurationListener
#com.company.qa.testngListeners.TestrunListener
com
.company.qa.testngListeners.TestcaseListener



My Listener class
@Slf4j
class ConfigurationListener implements IConfigurationListener2, IExecutionListener {
   
//------------------------------------------------------------------------
   
// TODO OUCH! I have this in TestcaseListener and likely in utils.  perhaps
   
// static ListenerUtils.methodToString
   
private String methodToString(ITestResult result) {
       
StringBuilder buf = new StringBuilder()
        buf
.append(result.getTestClass().getRealClass().getSimpleName())
        buf
.append('.')
        buf
.append(result.getName())
        buf
.append("(")
        buf
.append(result.getParameters()?.join(","))
        buf
.append(")")
       
return buf
   
}

   
static AtomicInteger total   = new AtomicInteger(0)    
   
static AtomicInteger success = new AtomicInteger(0)
   
static AtomicInteger failed  = new AtomicInteger(0)
   
static AtomicInteger skipped = new AtomicInteger(0)

   
@Override
   
public void onConfigurationSuccess(ITestResult tr) {
        success
.incrementAndGet()
       
// TODO --> if (log.traceEnabled) trace ...
        log
.warn "onConfigurationSuccess: " + methodToString(tr)
   
}

   
@Override
   
public void onConfigurationFailure(ITestResult tr) {
        failed
.incrementAndGet()
       
// TODO  maybe --> if (log.traceEnabled) trace ...
        log
.error "onConfigurationFailure: $tr"
   
}

   
@Override
   
public void onConfigurationSkip(ITestResult tr) {
        skipped
.incrementAndGet()
       
// TODO maybe --> if (log.traceEnabled) trace ...
        log
.warn "onConfigurationSkip: $tr"
   
}

   
@Override
   
public void beforeConfiguration(ITestResult tr) {
        total
.incrementAndGet()
       
// TODO --> if (log.traceEnabled) trace ...
        log
.debug "beforeConfiguration: " + methodToString(tr)
       
// TODO --> if (log.traceEnabled) trace ...
        log
.warn "beforeConfiguration: $tr"
   
}
   
@Override
   
public void onExecutionStart() {
       
// TODO --> if (log.traceEnabled) trace ...
        log
.warn "onExecutionStart()"
   
}
   
@Override
   
public void onExecutionFinish() {
       
def t = total.get()
       
def g = success.get()
       
def f = failed.get()
       
def s = skipped.get()
       
// TODO --> if (log.debugEnabled) debug ...
        log
.warn "onExecutionFinish: configurations run $t, succeeded: $g, failed: $f, skipped: $s"
   
}



jmcgrail

unread,
Nov 8, 2016, 12:03:05 PM11/8/16
to testng-users
I should also mention that my original version of this implemented only IConfigurationListener2.  I added IExecutionListener during debugging just to see that the class was being loaded for something.

Cédric Beust ♔

unread,
Nov 8, 2016, 3:23:05 PM11/8/16
to testng...@googlegroups.com, XuQing Tan
Adding Nick in Cc since this looks related to Eclipse.

-- 
Cédric


On Tue, Nov 8, 2016 at 9:03 AM, jmcgrail <jmcg...@gmail.com> wrote:
I should also mention that my original version of this implemented only IConfigurationListener2.  I added IExecutionListener during debugging just to see that the class was being loaded for something.

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

XuQing Tan

unread,
Nov 8, 2016, 7:26:59 PM11/8/16
to testng-users
Do you have any configuration excludes the specific listener in eclipse?

jmcgrail

unread,
Nov 9, 2016, 2:08:47 PM11/9/16
to testng-users
Hi,


On Tuesday, November 8, 2016 at 7:26:59 PM UTC-5, XuQing Tan wrote:
Do you have any configuration excludes the specific listener in eclipse?

I'm not sure what you're asking.  I've only ever added configurations, never excluded them.

I'll try to put together a java class for the listener and a sample test class along with some instructions to replicate what I'm seeing, but it'll be a few days as I'm under a tight deadline at the moment.

But, simply put ... The ConfigurationListener2 methods are not being from within eclipse regardless of whether
1. the ConfigurationListener2 class is specified in the services file
2. the ConfigurationListener2 class is specified in the Windows | Preferences | TestNG | Pre defined Listeners field in eclipse
I have, however, found, that
1. a fat jar with the same services file that eclipse sees, the ConfigurationListener2 is invoked when invoked from a java command line..
2. if I add @Listeneber(MyClass)  annotation to a test class, eclipse test runs will invoke the listener
3. other listeners (particular testrun and testcase variants) listed in the services file are invoked by eclipse.

Thanks,
John

XuQing Tan

unread,
Nov 19, 2016, 8:41:30 PM11/19/16
to testng-users
I'm working on the fix, please track the ticket: https://github.com/cbeust/testng-eclipse/issues/298

XuQing Tan

unread,
Nov 21, 2016, 7:20:02 PM11/21/16
to testng-users
hi jmcgrail
the fix is now available on the beta update site: http://testng.org/eclipse-beta
please let's know how is this going.
thanks


On Wednesday, November 9, 2016 at 11:08:47 AM UTC-8, jmcgrail wrote:

jmcgrail

unread,
Dec 30, 2016, 11:40:43 AM12/30/16
to testng-users

I can confirm fixed using testng 6.10, eclipse plugin 6.10.0.201612030230, and eclipse neon.1a (aka 4.6.1).


thanks everyone!

Reply all
Reply to author
Forward
0 new messages