IInvokedMethodListener expects all config and testmethods to be on implementing class

22 views
Skip to first unread message

Tarun Kumar

unread,
Oct 13, 2016, 5:09:33 AM10/13/16
to testng-users

I am using IInvokedMethodListener of TestNG to carryout certain operations after execution of a test method -

public class MyListener implements IInvokedMethodListener {

@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
  // some magic here
}

@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
  // some magic here  
}

But execution of tests using mvn test results in following errors -

java.lang.NoSuchMethodException: com.savingglobal.opsys.webui.util.MyListener.springTestContextPrepareTestInstance java.lang.NoSuchMethodException: com.savingglobal.opsys.webui.util.MyListener.springTestContextBeforeTestMethod()

and all of the configuration methods and my test methods. Am I using the listener wrong? I am on TestNG 6.9.10

⇜Krishnan Mahadevan⇝

unread,
Oct 13, 2016, 5:13:49 AM10/13/16
to testng...@googlegroups.com
Tarun,

Can you please share the complete stacktrace ? With the stubbed listener code that you shared, its difficult to guess what could be going wrong. But on the face of it, it looks like the problem is perhaps not from the TestNG listener as such but the code path that the TestNG listener is executing.

Just to confirm this, can you quickly stub out all the real code in your listener, add some sysouts and check if the sysouts are getting printed ?


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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.

Tarun Kumar

unread,
Oct 13, 2016, 8:18:46 AM10/13/16
to testng-users
Some more debugging and found that error is from following line when I construct Method object

public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
Method testMethod = getClass().getMethod(testResult.getName());
}

Since MyListener does not have springTestContextBeforeTestClass config method hence I get this error. but then
how do I get reference of testMethod ?

The stacktrace for config method - springTestContextBeforeTestClass (and many similar stacktraces for each config method
and eventually testMethod).

java.lang.NoSuchMethodException: com.savingglobal.opsys.webui.util.MyListener.springTestContextBeforeTestClass()
at java.lang.Class.getMethod(Class.java:1670)
at com.savingglobal.opsys.webui.util.MyListener.afterInvocation(MyListener.java:34)



On Thursday, October 13, 2016 at 11:13:49 AM UTC+2, Krishnan wrote:
Tarun,

Can you please share the complete stacktrace ? With the stubbed listener code that you shared, its difficult to guess what could be going wrong. But on the face of it, it looks like the problem is perhaps not from the TestNG listener as such but the code path that the TestNG listener is executing.

Just to confirm this, can you quickly stub out all the real code in your listener, add some sysouts and check if the sysouts are getting printed ?


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Thu, Oct 13, 2016 at 2:39 PM, Tarun Kumar <tku...@gmail.com> wrote:

I am using IInvokedMethodListener of TestNG to carryout certain operations after execution of a test method -

public class MyListener implements IInvokedMethodListener {

@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
  // some magic here
}

@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
  // some magic here  
}

But execution of tests using mvn test results in following errors -

java.lang.NoSuchMethodException: com.savingglobal.opsys.webui.util.MyListener.springTestContextPrepareTestInstance java.lang.NoSuchMethodException: com.savingglobal.opsys.webui.util.MyListener.springTestContextBeforeTestMethod()

and all of the configuration methods and my test methods. Am I using the listener wrong? I am on TestNG 6.9.10

--
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...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Oct 13, 2016, 8:25:29 AM10/13/16
to testng...@googlegroups.com
Tarun,

The line : Method testMethod = getClass().getMethod(testResult.getName());
is basically trying to search for a method name as returned by testResult.getName() in your listener [ getClass() within a listener would cause Java to refer to the listener class ]

If you basically want to figure out the testMethod that was invoked just before afterInvocation() was invoked you should be doing

Method method = testResult.getMethod().getConstructorOrMethod().getMethod(); //here testResult is of type ITestResult

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.

Tarun Kumar

unread,
Oct 13, 2016, 9:16:23 AM10/13/16
to testng-users
awesome works well. Thanks a ton.
Reply all
Reply to author
Forward
0 new messages