ITestResult missing exception message + stack when tests get skipped during the Before hooks

110 views
Skip to first unread message

Ish Abbi

unread,
Mar 10, 2021, 3:24:11 PM3/10/21
to testng-users

Hi,

I'm using TestNG with  Selenium for executing tests. I've noticed that in case my tests fail inside the @Before hooks the tests get marked as "skipped" but I don't get any throwable object in the ITestResult instance of my @After hooks (It fails with a null pointer).

Screenshot 2021-03-11 at 1.28.38 AM.png

The full stacktrace + exception message is however present in the resulting testng-results.xml.
Screenshot 2021-03-11 at 1.49.51 AM.png

Can someone please help me with what could be the reason for this behavior? And what can be done to obtain the throwable in case my tests get skipped?

Thanks,
Ish

⇜Krishnan Mahadevan⇝

unread,
Mar 11, 2021, 1:46:43 AM3/11/21
to testng-users
What version of TestNG are you working with? Can you please make sure you are using the latest released version ( 7.4.0 as of today) and try again ?
If the problem persists, please help share a sample that can be used to recreate the problem.

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 Scribblings @ https://rationaleemotions.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/8a680d9e-4d98-486b-b7a4-fc3ba07e6d27n%40googlegroups.com.

Ish Abbi

unread,
Mar 11, 2021, 5:25:47 AM3/11/21
to testng...@googlegroups.com
Hi Krishnan,

Thank you for reaching out. I'm using the latest versions of TestNG. The issue I'm facing was present in the earlier versions as well.


Please let me know in case you need more information.

You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/ks9IcxZG_vg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/CANikZLmh0oOgumTMGYm7Gaw22Ryh%2BUuvgYApqE3_F%2Bdss-YKaA%40mail.gmail.com.

⇜Krishnan Mahadevan⇝

unread,
Mar 11, 2021, 5:56:32 AM3/11/21
to testng-users
Couple of things.

1. You need to use TestNG 7.4.0 (latest released)
2. You are trying to retrieve the Throwable object for a test method that was skipped, which explains why you are seeing a Null Value.

The Throwable object for a ITestResult would be populated ONLY if the test method failed. In your case your "@BeforeMethod" introduced a failure, which caused the test method to be skipped.

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 Scribblings @ https://rationaleemotions.com/

Ish Abbi

unread,
Mar 11, 2021, 6:10:11 AM3/11/21
to testng-users
Thanks Krishnan for clarifying the above.

Is there any provision using which I can get the Throwable objects of the @Before hooks ?

⇜Krishnan Mahadevan⇝

unread,
Mar 11, 2021, 6:28:30 AM3/11/21
to testng-users
You can try leveraging TestNG listeners instead of using "@BeforeMethod and @AfterMethod".

For e.g., IInvokedMethodListener using which you should be able to intercept the failure reasons of both test and configuration methods by inspecting the test result and if failure then querying the throwable object.

For methods that were skipped, you should be able to find out the upstream methods that caused a particular method to be skipped by checking ITestResult.getSkipCausedBy()

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 Scribblings @ https://rationaleemotions.com/

Ish Abbi

unread,
Mar 11, 2021, 1:23:55 PM3/11/21
to testng...@googlegroups.com
Thanks a lot Krishan, My queries and issues have been resolved :-)

Reply all
Reply to author
Forward
0 new messages