TestNG unable to detect IInvokedMethodListener

202 views
Skip to first unread message

S M Humayun

unread,
Nov 4, 2009, 6:52:02 AM11/4/09
to testng-users
Hi,

I created a class that implements both IInvokedMethodListener and
ITestListener:

public class TestMethodListener implements IInvokedMethodListener,
ITestListener

And then configured it as follows:

<suite...>
<listeners>
<listener class-
name="com.iblgrp.common.core.test.helper.TestMethodListener"/>
</listeners>
<test...>
</suite>

When I ran tests only ITestListener callback methods were called and
not those of IInvokedMethodListener. Is it supposed to work that way
or am I missing some thing?

regards,

Humayun.

Cédric Beust ♔

unread,
Nov 4, 2009, 1:08:50 PM11/4/09
to testng...@googlegroups.com
Hi Humayun,

I just tested with a class that implements both interfaces and I see all the callbacks being invoked correctly.

Are you using Eclipse?  Can you try with the command line only?

--
Cédric

Pranav

unread,
Nov 4, 2009, 6:51:41 PM11/4/09
to testng...@googlegroups.com
List,

I was trying to implement IAnnotationTransformer2 based listener for my
TestNG Factory. Right now though my factory runs multiple testcases,
the listener only gets called once. it calls both of the following
method once

public void transform(ITestAnnotation annotation, Class
testClass,Constructor testConstructor, Method testMethod)
public void transform(IFactoryAnnotation arg0, Method arg1)

but I was expecting it to call them once for each testcase.

just to give you guys context, I am trying to transform group
annotations for each of my @factory testcase.

is there some other way to achieve it?

Best,
Pranav

Cédric Beust ♔

unread,
Nov 4, 2009, 6:57:58 PM11/4/09
to testng...@googlegroups.com
Can you post the source of your factory and your XML file?

Thanks.

--
Cedric
--
Cédric


Pranav

unread,
Nov 4, 2009, 8:28:37 PM11/4/09
to testng...@googlegroups.com
i have attached the zipped src folder with this mail. please have a
look. if you run it , you will see this output

java -classpath .:../Lib/testng-5.9-jdk15.jar org.testng.TestNG testng.xml
[Parser] Running:
Itest/src/testng.xml

called : transform(IFactoryAnnotation arg0, Method arg1)
called : transform(ITestAnnotation annotation, Class
testClass,Constructor testConstructor, Method testMethod)
ITest:getTestName Called
ITest:getTestName Called
ITest:getTestName Called
ITest:getTestName Called
ITest:getTestName Called
PASSED: someTest (Test1)
PASSED: someTest (Test4)
PASSED: someTest (Test0)
PASSED: someTest (Test3)
PASSED: someTest (Test2)

===============================================
ItestDemo
Tests run: 5, Failures: 0, Skips: 0
===============================================


===============================================
testSuite
Total tests run: 5, Failures: 0, Skips: 0
===============================================
> **/*Cédric*
> /
>
>
> >

src.zip

S M Humayun

unread,
Nov 4, 2009, 11:27:57 PM11/4/09
to testng-users
I am using TestNG 5.9 with Maven Surefire Plugin configured as
follows:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</
suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

Do note that I didn't mention any version in the plugin config above.

I've already posted the testng.xml in my previous email quoted below
and I am using JetBrain's Intellij IDEA.

- Humayun.

On Nov 4, 11:08 pm, Cédric Beust ♔ <cbe...@google.com> wrote:
> Hi Humayun,
>
> I just tested with a class that implements both interfaces and I see all the
> callbacks being invoked correctly.
>
> Are you using Eclipse?  Can you try with the command line only?
>
> --
> ***Cédric
> *

Cédric Beust ♔

unread,
Nov 4, 2009, 11:35:37 PM11/4/09
to testng...@googlegroups.com
Can you try without Surefire?  This Maven plug-in seems to cause a lot of problems...

--
Cedric
--
Cédric


Pranav

unread,
Nov 5, 2009, 2:51:31 AM11/5/09
to Pranav, testng...@googlegroups.com
on second thoughts, this is never suppose to happen, coz if I understand
right, testng scans/loads annotations at the start, hence transforming
should happen at that time only....and I wanted to change them during
the test run. It probably against the design to up[date the annotations
during test execution... can somebody please confirm that ?


right now we have implemented groups feature, by adding some custom
filtering logic in my Factory class...... it works just fine for us .

Best,
Pranav

Cédric Beust ♔

unread,
Nov 5, 2009, 2:59:21 AM11/5/09
to testng...@googlegroups.com, Pranav
Hi Pranav,

On Wed, Nov 4, 2009 at 11:51 PM, Pranav <pranav...@gmail.com> wrote:

on second thoughts, this is never suppose to happen, coz if I understand
right, testng scans/loads annotations at the start, hence transforming
should happen at that time only....and I wanted to change them during
the test run. It probably against the design to up[date the annotations
during test execution... can somebody please confirm that ?


Correct, the annotation transformers modify the annotations before the TestNG engine sees them.

--
Cédric


Pranav

unread,
Nov 5, 2009, 3:45:17 AM11/5/09
to Cédric Beust ♔, testng...@googlegroups.com
Thanks for the confirmation Cédric :)

Best,
Pranav

> **/*Cédric*
> /
>

S M Humayun

unread,
Nov 5, 2009, 4:21:03 AM11/5/09
to testng...@googlegroups.com
Are there any other plugins available to integrate Maven with TestNG?

Though, I've managed to do the same using ITestListener, which is
working fine. Actually, I just wanted to log following:

--- <TestMethodName> : START ---

before test and following:

--- <TestMethodName> : END ---

after test.

You might ask why I didn't use @Before and @After annotations, thats
because I didn't find a way to get the actual test method name and
then I stumble upon IInvokedMethodListener and ITestListener and the
later one did the trick for me. Is there a better way of doing this?
provided that I have to use TestNG with Maven.

--------------------------------------------
S M Humayun
Software Architect, IBL Group
--------------------------------------------
Email : smhu...@iblgrp.com
MSN : smhuma...@hotmail.com
Skype : smhumayun
Cell : 92.321.8707783
Blog : http://smhumayun.blogspot.com
Link : http://www.linkedin.com/in/smhumayun
Facebook : http://www.facebook.com/smhumayun
Twitter : http://twitter.com/smhumayun
--------------------------------------------





2009/11/5 Cédric Beust ♔ <cbe...@google.com>:

Cédric Beust ♔

unread,
Nov 5, 2009, 10:48:54 AM11/5/09
to testng...@googlegroups.com
On Thu, Nov 5, 2009 at 1:21 AM, S M Humayun <smhu...@gmail.com> wrote:

Are there any other plugins available to integrate Maven with TestNG?

Though, I've managed to do the same using ITestListener, which is
working fine. Actually, I just wanted to log following:

--- <TestMethodName> : START ---

before test and following:

--- <TestMethodName> : END ---

after test.

You might ask why I didn't use @Before and @After annotations, thats
because I didn't find a way to get the actual test method name

Just declare a parameter of type Method in your @BeforeMethod and TestNG will inject the test method for you.

--
Cédric


S M Humayun

unread,
Nov 6, 2009, 12:19:31 AM11/6/09
to testng...@googlegroups.com
Thanx for the pointer.

I am using 5.9, which does not supports ITestResult parameter
injection in @AfterMethod and I tried using Method parameter injection
and it works ! However, nowhere in the doc
(http://testng.org/doc/documentation-main.html#dependency-injection)
is mentioned that @AfterMethod also supports Method parameter
injection.

--------------------------------------------
S M Humayun
Software Architect, IBL Group
--------------------------------------------
Email : smhu...@iblgrp.com
MSN : smhuma...@hotmail.com
Skype : smhumayun
Cell : 92.321.8707783
Blog : http://smhumayun.blogspot.com
Link : http://www.linkedin.com/in/smhumayun
Facebook : http://www.facebook.com/smhumayun
Twitter : http://twitter.com/smhumayun
--------------------------------------------





2009/11/5 Cédric Beust ♔ <cbe...@google.com>:
>
>

Cédric Beust ♔

unread,
Nov 6, 2009, 12:25:50 AM11/6/09
to testng...@googlegroups.com
On Thu, Nov 5, 2009 at 9:19 PM, S M Humayun <smhu...@gmail.com> wrote:

Thanx for the pointer.

I am using 5.9, which does not supports ITestResult parameter
injection in @AfterMethod and I tried using Method parameter injection
and it works ! However, nowhere in the doc
(http://testng.org/doc/documentation-main.html#dependency-injection)
is mentioned that @AfterMethod also supports Method parameter
injection.

Good catch, I must have missed it.  I fixed it on the web site.

Thanks!

--
Cédric


Reply all
Reply to author
Forward
0 new messages